Foreword |
|
xv | |
Preface |
|
xvii | |
Acknowledgments |
|
xix | |
About This Book |
|
xxi | |
About The Author |
|
xxv | |
About The Cover Illustration |
|
xxvi | |
Part 1 First Steps |
|
1 | (100) |
|
|
3 | (20) |
|
1.1 Why is Unity so great? |
|
|
4 | (6) |
|
Unity's strengths and advantages |
|
|
4 | (2) |
|
|
6 | (1) |
|
Example games built with Unity |
|
|
7 | (3) |
|
|
10 | (6) |
|
Scene view, Game view, and the Toolbar |
|
|
12 | (2) |
|
|
14 | (1) |
|
The Hierarchy view and the Inspector panel |
|
|
15 | (1) |
|
The Project and Console tabs |
|
|
16 | (1) |
|
1.3 Getting up and running with Unity programming |
|
|
16 | (7) |
|
Running code in Unity: Script components |
|
|
17 | (1) |
|
Using Visual Studio, the included IDE |
|
|
18 | (1) |
|
Printing to the console: Hello World! |
|
|
19 | (4) |
|
2 Building a demo that puts you in 3D space |
|
|
23 | (27) |
|
|
24 | (3) |
|
|
24 | (1) |
|
Understanding 3D coordinate space |
|
|
25 | (2) |
|
2.2 Begin the project: Place objects in the scene |
|
|
27 | (6) |
|
The scenery: Floor, outer walls, and inner walls |
|
|
28 | (2) |
|
|
30 | (2) |
|
The player's collider and viewpoint |
|
|
32 | (1) |
|
2.3 Make things move: A script that applies transforms |
|
|
33 | (4) |
|
Visualizing how movement is programmed |
|
|
33 | (1) |
|
Writing code to implement the diagram |
|
|
34 | (1) |
|
Understanding local vs. global coordinate space |
|
|
35 | (2) |
|
2.4 Script component for looking around: MouseLook |
|
|
37 | (7) |
|
Horizontal rotation that tracks mouse movement |
|
|
38 | (1) |
|
Vertical rotation with limits |
|
|
39 | (2) |
|
Horizontal and vertical rotation at the same time |
|
|
41 | (3) |
|
2.5 Keyboard input component: First-person controls |
|
|
44 | (6) |
|
|
44 | (1) |
|
Setting a rate of movement independent of the computer's speed |
|
|
45 | (1) |
|
Moving the CharacterController for collision detection |
|
|
46 | (1) |
|
Adjusting components for walking instead of flying |
|
|
47 | (3) |
|
3 Adding enemies and projectiles to the 3D game |
|
|
50 | (25) |
|
3.1 Shooting via raycasts |
|
|
51 | (6) |
|
|
51 | (1) |
|
Using the ScreenPoint ToRay command for shooting |
|
|
52 | (2) |
|
Adding visual indicators for aiming and hits |
|
|
54 | (3) |
|
3.2 Scripting reactive targets |
|
|
57 | (3) |
|
|
57 | (1) |
|
Alerting the target that it was hit |
|
|
58 | (2) |
|
|
60 | (4) |
|
Diagramming how basic Al works |
|
|
60 | (1) |
|
"Seeing" obstacles with a raycast |
|
|
61 | (1) |
|
Tracking the character's state |
|
|
62 | (2) |
|
3.4 Spawning enemy prefabs |
|
|
64 | (4) |
|
|
64 | (1) |
|
Creating the enemy prefab |
|
|
65 | (1) |
|
Instantiating from an invisible SceneController |
|
|
65 | (3) |
|
3.5 Shooting by instantiating objects |
|
|
68 | (7) |
|
Creating the projectile prefab |
|
|
68 | (2) |
|
Shooting the projectile and colliding with a target |
|
|
70 | (3) |
|
|
73 | (2) |
|
4 Developing graphics for your game |
|
|
75 | (26) |
|
4.1 Understanding art assets |
|
|
76 | (2) |
|
4.2 Building basic 3D scenery: Whiteboxing |
|
|
78 | (4) |
|
|
79 | (1) |
|
Drawing a floor plan for the level |
|
|
79 | (1) |
|
Laying out primitives according to the plan |
|
|
80 | (2) |
|
4.3 Texturing the scene with 2D images |
|
|
82 | (5) |
|
|
83 | (1) |
|
|
84 | (1) |
|
|
85 | (2) |
|
4.4 Generating sky visuals by using texture images |
|
|
87 | (3) |
|
|
87 | (1) |
|
Creating a new skybox material |
|
|
88 | (2) |
|
4.5 Working with custom 3D models |
|
|
90 | (5) |
|
Which file format to choose? |
|
|
91 | (1) |
|
Exporting and importing the model |
|
|
92 | (3) |
|
4.6 Creating effects by using particle systems |
|
|
95 | (8) |
|
Adjusting parameters on the default effect |
|
|
96 | (2) |
|
Applying a new texture for fire |
|
|
98 | (1) |
|
Attaching particle effects to 3D objects |
|
|
99 | (2) |
Part 2 Getting Comfortable |
|
101 | (126) |
|
5 Building a Memory game using Unity's 2D functionality |
|
|
103 | (25) |
|
5.1 Setting up everything for 2D graphics |
|
|
104 | (6) |
|
|
105 | (2) |
|
Displaying 2D images (aka sprites) |
|
|
107 | (1) |
|
Switching the camera to 2D mode |
|
|
108 | (2) |
|
5.2 Building a card object and making it react to clicks |
|
|
110 | (3) |
|
Building the object out of sprites |
|
|
110 | (1) |
|
|
111 | (1) |
|
Revealing the card on a click |
|
|
112 | (1) |
|
5.3 Displaying the various card images |
|
|
113 | (6) |
|
Loading images programmatically |
|
|
113 | (1) |
|
Setting the image from an invisible SceneController |
|
|
114 | (2) |
|
Instantiating a grid of cards |
|
|
116 | (2) |
|
|
118 | (1) |
|
5.4 Making and scoring matches |
|
|
119 | (4) |
|
Storing and comparing revealed cards |
|
|
120 | (1) |
|
|
120 | (1) |
|
Text display for the score |
|
|
121 | (2) |
|
|
123 | (5) |
|
Programming a UIButton component by using SendMessage |
|
|
124 | (2) |
|
Calling LoadScene from SceneController |
|
|
126 | (2) |
|
6 Creating a basic 2D playbrmer |
|
|
128 | (19) |
|
6.1 Setting up the graphics |
|
|
129 | (3) |
|
|
129 | (1) |
|
|
130 | (2) |
|
6.2 Moving the player left and right |
|
|
132 | (2) |
|
Writing keyboard controls |
|
|
133 | (1) |
|
|
134 | (1) |
|
6.3 Playing the sprite's animation |
|
|
134 | (3) |
|
Explaining the Mecanim animation system |
|
|
134 | (2) |
|
Triggering animations from code |
|
|
136 | (1) |
|
6.4 Adding the ability to jump |
|
|
137 | (3) |
|
|
137 | (1) |
|
Applying an upward impulse |
|
|
138 | (1) |
|
|
139 | (1) |
|
6.5 Additional features for a platform game |
|
|
140 | (7) |
|
Unusual floors: Slopes and one-way platforms |
|
|
140 | (2) |
|
Implementing moving platforms |
|
|
142 | (3) |
|
|
145 | (2) |
|
7 Putting a GUI onto a game |
|
|
147 | (24) |
|
7.1 Before you start writing code |
|
|
149 | (2) |
|
Immediate mode GUI or advanced 2D interface? |
|
|
149 | (1) |
|
|
150 | (1) |
|
|
151 | (1) |
|
7.2 Setting up the GUI display |
|
|
151 | (6) |
|
Creating a canvas for the interface |
|
|
151 | (2) |
|
Buttons, images, and text labels |
|
|
153 | (3) |
|
Controlling the position of UI elements |
|
|
156 | (1) |
|
7.3 Programming interactivity in the UI |
|
|
157 | (9) |
|
Programming an invisible UIController |
|
|
158 | (2) |
|
|
160 | (3) |
|
Setting values using sliders and input fields |
|
|
163 | (3) |
|
7.4 Updating the game by responding to events |
|
|
166 | (5) |
|
Integrating an event system |
|
|
166 | (1) |
|
Broadcasting and listening for events from the scene |
|
|
167 | (1) |
|
Broadcasting and listening for events from the HUD |
|
|
168 | (3) |
|
8 Creating a third-person 3D game: Player movement and animation |
|
|
171 | (29) |
|
8.1 Adjusting the camera view for third-person |
|
|
173 | (7) |
|
Importing a character to look at |
|
|
174 | (1) |
|
Adding shadows to the scene |
|
|
175 | (2) |
|
Orbiting the camera around the player character |
|
|
177 | (3) |
|
8.2 Programming camera-relative movement controls |
|
|
180 | (4) |
|
Rotating the character to face movement direction |
|
|
180 | (3) |
|
Moving forward in that direction |
|
|
183 | (1) |
|
8.3 Implementing the jump action |
|
|
184 | (6) |
|
Applying vertical speed and acceleration |
|
|
185 | (1) |
|
Modifying the ground detection to handle edges and slopes |
|
|
186 | (4) |
|
8.4 Setting up animations on the player character |
|
|
190 | (10) |
|
Defining animation clips in the imported model |
|
|
192 | (2) |
|
Creating the animator controller for these animations |
|
|
194 | (3) |
|
Writing code that operates the animator |
|
|
197 | (3) |
|
9 Adding interactive devices and items within the game |
|
|
200 | (27) |
|
9.1 Creating doors and other devices |
|
|
201 | (5) |
|
Doors that open and close on a keypress |
|
|
201 | (2) |
|
Checking distance and facing before opening the door |
|
|
203 | (2) |
|
Operating a color-changing monitor |
|
|
205 | (1) |
|
9.2 Interacting with objects by bumping into them |
|
|
206 | (6) |
|
Colliding with physics-enabled obstacles |
|
|
206 | (1) |
|
Operating the door with a trigger object |
|
|
207 | (3) |
|
Collecting items scattered around the level |
|
|
210 | (2) |
|
9.3 Managing inventory data and game state |
|
|
212 | (8) |
|
Setting up player and inventory managers |
|
|
212 | (2) |
|
Programming the game managers |
|
|
214 | (3) |
|
Storing inventory in a collection object: List vs. Dictionary |
|
|
217 | (3) |
|
9.4 Inventory UI for using and equipping items |
|
|
220 | (9) |
|
Displaying inventory items in the UI |
|
|
220 | (3) |
|
Equipping a key to use on locked doors |
|
|
223 | (1) |
|
Restoring the player's health by consuming health packs |
|
|
224 | (3) |
Part 3 Strong Finish |
|
227 | (122) |
|
10 Connecting your game to the internet |
|
|
229 | (28) |
|
10.1 Creating an outdoor scene |
|
|
231 | (4) |
|
Generating sky visuals by using a skybox |
|
|
231 | (1) |
|
Setting up an atmosphere that's controlled by code |
|
|
232 | (3) |
|
10.2 Downloading weather data from an internet service |
|
|
235 | (12) |
|
Requesting HTTP data using coroutines |
|
|
238 | (4) |
|
|
242 | (1) |
|
|
243 | (3) |
|
Affecting the scene based on weather data |
|
|
246 | (1) |
|
10.3 Adding a networked billboard |
|
|
247 | (6) |
|
Loading images from the internet |
|
|
247 | (3) |
|
Displaying images on the billboard |
|
|
250 | (1) |
|
Caching the downloaded image for reuse |
|
|
251 | (2) |
|
10.4 Posting data to a web server |
|
|
253 | (4) |
|
Tracking current weather: Sending post requests |
|
|
254 | (1) |
|
|
255 | (2) |
|
11 Playing audio: Sound effects and music |
|
|
257 | (25) |
|
11.1 Importing sound effects |
|
|
258 | (3) |
|
|
258 | (2) |
|
|
260 | (1) |
|
11.2 Playing sound effects |
|
|
261 | (4) |
|
Explaining what's involved: Audio clip vs. source vs. listener |
|
|
261 | (2) |
|
Assigning a looping sound |
|
|
263 | (1) |
|
Triggering sound effects from code |
|
|
264 | (1) |
|
11.3 Using the audio control interface |
|
|
265 | (7) |
|
Setting up the central AudioManager |
|
|
265 | (2) |
|
|
267 | (4) |
|
|
271 | (1) |
|
11.4 Adding background music |
|
|
272 | (10) |
|
|
272 | (4) |
|
Controlling music volume separately |
|
|
276 | (2) |
|
|
278 | (4) |
|
12 Putting the parts together into a complete game |
|
|
282 | (32) |
|
12.1 Building an action RPG by repurposing projects |
|
|
283 | (16) |
|
Assembling assets and code from multiple projects |
|
|
284 | (2) |
|
Programming point-and-click controls: Movement and devices |
|
|
286 | (6) |
|
Replacing the old GUI with a new interface |
|
|
292 | (7) |
|
12.2 Developing the overarching game structure |
|
|
299 | (8) |
|
Controlling mission flow and multiple levels |
|
|
299 | (4) |
|
Completing a level by reaching the exit |
|
|
303 | (2) |
|
Losing the level when caught by enemies |
|
|
305 | (2) |
|
12.3 Handling the player's progression through the game |
|
|
307 | (7) |
|
Saving and loading the player's progress |
|
|
307 | (4) |
|
Beating the game by completing three levels |
|
|
311 | (3) |
|
13 Deploying your game to players' devices |
|
|
314 | (35) |
|
13.1 Start by building for the desktop: Windows, Mac, and Linux |
|
|
317 | (4) |
|
|
317 | (1) |
|
Adjusting player settings: Setting the game's name and icon |
|
|
318 | (1) |
|
Platform-dependent compilation |
|
|
319 | (2) |
|
13.2 Building for the web |
|
|
321 | (4) |
|
Building the game embedded in a web page |
|
|
321 | (1) |
|
Communicating with JavaScript in the browser |
|
|
322 | (3) |
|
13.3 Building for mobile: iOS and Android |
|
|
325 | (16) |
|
Setting up the build tools |
|
|
326 | (5) |
|
|
331 | (1) |
|
|
332 | (9) |
|
13.4 Developing XR (both VR and AR) |
|
|
341 | (8) |
|
Supporting virtual reality headsets |
|
|
341 | (1) |
|
AR Foundation for mobile Augmented Reality |
|
|
342 | (7) |
Afterword |
|
349 | (4) |
Appendix A Scene Navigation And Keyboard Shortcuts |
|
353 | (3) |
Appendix B External Tools Used Alongside Unity |
|
356 | (4) |
Appendix C Modeling A Bench In Blender |
|
360 | (9) |
Appendix D Online Learning Resources |
|
369 | (4) |
Index |
|
373 | |