Table of Contents
Preface ix
Part I The Basics of Unity
1 Introducing Unity 3
Hello, Book 3
Hello, Unity 4
2 A Tour of Unity 7
The Editor 7
The Scene View 11
The Hierarchy 14
The Project View 15
The Inspector 17
The Game View 19
Wrapping Up 19
3 Scripting in Unity 21
A Crash Course in C# 22
Mono and Unity 23
Game Objects, Components, and Scripts 25
Important Methods 28
Coroutines 31
Creating and Destroying Objects 33
Attributes 36
Time in Scripts 39
Logging to the Console 40
Wrapping Up 40
Part II Building a 2D Game: Gnome on a Rope
4 Getting Started Building the Game 43
Game Design 44
Creating the Project and Importing Assets 50
Creating the Gnome 52
Rope 61
Wrapping Up 77
5 Preparing for Gameplay 79
Input 79
Setting Up the Gnome's Code 96
Setting Up the Game Manager 109
Preparing the Scene 122
Wrapping Up 124
6 Building Gameplay with Traps and Objectives 125
Simple Traps 125
Treasure and Exit 127
Adding a Background 133
Wrapping Up 134
7 Polishing the Game 137
Updating the Gnome's Art 138
Updating the Physics 142
Background 150
User Interface 161
Invincibility Mode 171
Wrapping Up 173
8 Final Touches on Gnome's Well 175
More Traps and Level Objects 175
Particle Effects 182
Main Menu 189
Audio 196
Wrapping Up and Challenges 197
Part III Building a 3D Game: Space Shooter
9 Building a Space Shooter 203
Designing the Game 204
Architecture 209
Creating the Scene 210
Wrapping Up 226
10 Input and Flight Control 227
Input 227
Flight Control 233
Wrapping Up 243
11 Adding Weapons and Targeting 245
Weapons 245
Target Reticle 263
Wrapping Up 264
12 Asteroids and Damage 265
Asteroids 265
Damage-Dealing and Taking 272
Wrapping Up 284
13 Audio, Menus, Death, and Explosions! 285
Menus 285
Game Manager and Death 291
Boundaries 303
Final Polish 311
Wrapping Up 322
Part IV Advanced features
14 Lighting and Shaders 325
Materials and Shaders 325
Global Illumination 340
Thinking About Performance 347
Wrapping Up 353
15 Creating GUIs in Unity 355
How GUIs Work in Unity 355
Controls 362
Events and Raycasts 362
Using the Layout System 364
Scaling the Canvas 36?
Transitioning Between Screens 369
Wrapping Up 369
16 Editor Extensions 371
Making a Custom Wizard 373
Making a Custom Editor Window 382
Making a Custom Property Drawer 395
Making a Custom Inspector 404
Wrapping Up 410
17 Beyond the Editor 411
The Unity Services Ecosystem 411
Deployment 424
Where to Go from Here 435
Index 437