Table of Contents for
Unity in Action, Second Edition
Close
Version ebook
/
Retour
Unity in Action, Second Edition
by Joseph Hocking
Published by Manning Publications, 2018
Cover
Unity in Action
Praise for the First Edition
Titlepage
Copyright
foreword
preface
acknowledgments
about this book
about the author
about the cover illustration
Part 1: First steps
Chapter 1: Getting to know Unity
Chapter 2: Building a demo that puts you in 3D space
Chapter 3: Adding enemies and projectiles to the 3D game
Chapter 4: Developing graphics for your game
Part 2: Getting comfortable
Chapter 5: Building a Memory game using Unity’s 2D functionality
Chapter 6: Creating a basic 2D platformer
Chapter 7: Putting a GUI onto a game
Chapter 8: Creating a third-person 3D game: player movement and animation
Chapter 9: Adding interactive devices and items within the game
Part 3: Strong finish
Chapter 10: Connecting your game to the internet
Chapter 11: Playing audio: sound effects and music
Chapter 12: Putting the parts together into a complete game
Chapter 13: Deploying your game to players’ devices
afterword
Appendix A: Scene navigation and keyboard shortcuts
Appendix B: External tools used alongside Unity
Appendix C: Modeling a bench in Blender
Appendix D: Online learning resources
Index
Prev
Previous Chapter
Cover
Next
Next Chapter
Praise for the First Edition
contents
Praise for the First Edition
Titlepage
Copyright
foreword
preface
acknowledgments
about this book
Roadmap
Code conventions, requirements, and downloads
Book forum
about the author
about the cover illustration
Part 1: First steps
Chapter 1: Getting to know Unity
1.1 Why is Unity so great?
1.1.1 Unity's strengths and advantages
1.1.2 Downsides to be aware of
1.1.3 Example games built with Unity
1.2 How to use Unity
1.2.1 Scene view, Game view, and the Toolbar
1.2.2 Using the mouse and keyboard
1.2.3 The Hierarchy view and the Inspector panel
1.2.4 The Project and Console tabs
1.3 Getting up and running with Unity programming
1.3.1 How code runs in Unity: script components
1.3.2 Using MonoDevelop, the cross-platform IDE
1.3.3 Printing to the console: Hello World!
Summary
Chapter 2: Building a demo that puts you in 3D space
2.1 Before you start …
2.1.1 Planning the project
2.1.2 Understanding 3D coordinate space
2.2 Begin the project: place objects in the scene
2.2.1 The scenery: floor, outer walls, and inner walls
2.2.2 Lights and cameras
2.2.3 The player’s collider and viewpoint
2.3 Making things move: a script that applies transforms
2.3.1 Visualizing how movement is programmed
2.3.2 Writing code to implement the diagram
2.3.3 Local vs. global coordinate space
2.4 Script component for looking around: MouseLook
2.4.1 Horizontal rotation that tracks mouse movement
2.4.2 Vertical rotation with limits
2.4.3 Horizontal and vertical rotation at the same time
2.5 Keyboard input component: first-person controls
2.5.1 Responding to keypresses
2.5.2 Setting a rate of movement independent of the computer’s speed
2.5.3 Moving the CharacterController for collision detection
2.5.4 Adjusting components for walking instead of flying
Summary
Chapter 3: Adding enemies and projectiles to the 3D game
3.1 Shooting via raycasts
3.1.1 What is raycasting?
3.1.2 Using the ScreenPointToRay command for shooting
3.1.3 Adding visual indicators for aiming and hits
3.2 Scripting reactive targets
3.2.1 Determining what was hit
3.2.2 Alert the target that it was hit
3.3 Basic wandering AI
3.3.1 Diagramming how basic AI works
3.3.2 “Seeing” obstacles with a raycast
3.3.3 Tracking the character’s state
3.4 Spawning enemy prefabs
3.4.1 What is a prefab?
3.4.2 Creating the enemy prefab
3.4.3 Instantiating from an invisible SceneController
3.5 Shooting by instantiating objects
3.5.1 Creating the projectile prefab
3.5.2 Shooting the projectile and colliding with a target
3.5.3 Damaging the player
Summary
Chapter 4: Developing graphics for your game
4.1 Understanding art assets
4.2 Building basic 3D scenery: whiteboxing
4.2.1 Whiteboxing explained
4.2.2 Drawing a floor plan for the level
4.2.3 Laying out primitives according to the plan
4.3 Texture the scene with 2D images
4.3.1 Choosing a file format
4.3.2 Importing an image file
4.3.3 Applying the image
4.4 Generating sky visuals using texture images
4.4.1 What is a skybox?
4.4.2 Creating a new skybox material
4.5 Working with custom 3D models
4.5.1 Which file format to choose?
4.5.2 Exporting and importing the model
4.6 Creating effects using particle systems
4.6.1 Adjusting parameters on the default effect
4.6.2 Applying a new texture for fire
4.6.3 Attaching particle effects to 3D objects
Summary
Part 2: Getting comfortable
Chapter 5: Building a Memory game using Unity’s 2D functionality
5.1 Setting everything up for 2D graphics
5.1.1 Preparing the project
5.1.2 Displaying 2D images (aka sprites)
5.1.3 Switching the camera to 2D mode
5.2 Building a card object and making it react to clicks
5.2.1 Building the object out of sprites
5.2.2 Mouse input code
5.2.3 Revealing the card on click
5.3 Displaying the various card images
5.3.1 Loading images programmatically
5.3.2 Setting the image from an invisible SceneController
5.3.3 Instantiating a grid of cards
5.3.4 Shuffling the cards
5.4 Making and scoring matches
5.4.1 Storing and comparing revealed cards
5.4.2 Hiding mismatched cards
5.4.3 Text display for the score
5.5 Restart button
5.5.1 Programming a UIButton component using SendMessage
5.5.2 Calling LoadScene from SceneController
Summary
Chapter 6: Creating a basic 2D platformer
6.1 Setting up the graphics
6.1.1 Placing the walls and floor
6.1.2 Importing sprite sheets
6.2 Moving the player left and right
6.2.1 Writing keyboard controls
6.2.2 Colliding with the walls
6.3 Playing the sprite’s animation
6.3.1 Explaining the Mecanim animation system
6.3.2 Triggering animations from code
6.4 Adding the ability to jump
6.4.1 Falling from gravity
6.4.2 Applying an upward impulse
6.4.3 Detecting the ground
6.5 Additional features for a platform game
6.5.1 Unusual floors: slopes and one-way platforms
6.5.2 Implementing moving platforms
6.5.3 Camera control
Summary
Chapter 7: Putting a GUI onto a game
7.1 Before you start writing code …
7.1.1 Immediate mode GUI or advanced 2D interface?
7.1.2 Planning the layout
7.1.3 Importing UI images
7.2 Setting up the GUI display
7.2.1 Creating a canvas for the interface
7.2.2 Buttons, images, and text labels
7.2.3 Controlling the position of UI elements
7.3 Programming interactivity in the UI
7.3.1 Programming an invisible UIController
7.3.2 Creating a pop-up window
7.3.3 Setting values using sliders and input fields
7.4 Updating the game by responding to events
7.4.1 Integrating an event system
7.4.2 Broadcasting and listening for events from the scene
7.4.3 Broadcasting and listening for events from the HUD
Summary
Chapter 8: Creating a third-person 3D game: player movement and animation
8.1 Adjusting the camera view for third-person
8.1.1 Importing a character to look at
8.1.2 Adding shadows to the scene
8.1.3 Orbiting the camera around the player character
8.2 Programming camera-relative movement controls
8.2.1 Rotating the character to face movement direction
8.2.2 Moving forward in that direction
8.3 Implementing the jump action
8.3.1 Applying vertical speed and acceleration
8.3.2 Modifying the ground detection to handle edges and slopes
8.4 Setting up animations on the player character
8.4.1 Defining animation clips in the imported model
8.4.2 Creating the animator controller for these animations
8.4.3 Writing code that operates the animator
Summary
Chapter 9: Adding interactive devices and items within the game
9.1 Creating doors and other devices
9.1.1 Doors that open and close on a keypress
9.1.2 Checking distance and facing before opening the door
9.1.3 Operating a color-changing monitor
9.2 Interacting with objects by bumping into them
9.2.1 Colliding with physics-enabled obstacles
9.2.2 Operating the door with a trigger object
9.2.3 Collecting items scattered around the level
9.3 Managing inventory data and game state
9.3.1 Setting up player and inventory managers
9.3.2 Programming the game managers
9.3.3 Storing inventory in a collection object: List vs. Dictionary
9.4 Inventory UI for using and equipping items
9.4.1 Displaying inventory items in the UI
9.4.2 Equipping a key to use on locked doors
9.4.3 Restoring the player’s health by consuming health packs
Summary
Part 3: Strong finish
Chapter 10: Connecting your game to the internet
10.1 Creating an outdoor scene
10.1.1 Generating sky visuals using a skybox
10.1.2 Setting up an atmosphere that’s controlled by code
10.2 Downloading weather data from an internet service
10.2.1 Requesting HTTP data using coroutines
10.2.2 Parsing XML
10.2.3 Parsing JSON
10.2.4 Affecting the scene based on weather data
10.3 Adding a networked billboard
10.3.1 Loading images from the internet
10.3.2 Displaying images on the billboard
10.3.3 Caching the downloaded image for reuse
10.4 Posting data to a web server
10.4.1 Tracking current weather: sending post requests
10.4.2 Server-side code in PHP
Summary
Chapter 11: Playing audio: sound effects and music
11.1 Importing sound effects
11.1.1 Supported file formats
11.1.2 Importing audio files
11.2 Playing sound effects
11.2.1 Explaining what’s involved: Audio Clip vs. Source vs. Listener
11.2.2 Assigning a looping sound
11.2.3 Triggering sound effects from code
11.3 Audio control interface
11.3.1 Setting up the central AudioManager
11.3.2 Volume control UI
11.3.3 Playing UI sounds
11.4 Background music
11.4.1 Playing music loops
11.4.2 Controlling music volume separately
11.4.3 Fading between songs
Summary
Chapter 12: Putting the parts together into a complete game
12.1 Building an action RPG by repurposing projects
12.1.1 Assembling assets and code from multiple projects
12.1.2 Programming point-and-click controls: movement and devices
12.1.3 Replacing the old GUI with a new interface
12.2 Developing the overarching game structure
12.2.1 Controlling mission flow and multiple levels
12.2.2 Completing a level by reaching the exit
12.2.3 Losing the level when caught by enemies
12.3 Handling the player’s progression through the game
12.3.1 Saving and loading the player’s progress
12.3.2 Beating the game by completing three levels
Summary
Chapter 13: Deploying your game to players’ devices
13.1 Start by building for the desktop: Windows, Mac, and Linux
13.1.1 Building the application
13.1.2 Adjusting Player Settings: setting the game’s name and icon
13.1.3 Platform-dependent compilation
13.2 Building for the web
13.2.1 Unity Player vs. HTML5/WebGL
13.2.2 Building the game embedded in a web page
13.2.3 Communicating with JavaScript in the browser
13.3 Building for mobile: iOS and Android
13.3.1 Setting up the build tools
13.3.2 Texture compression
13.3.3 Developing plug-ins
Summary
afterword
Game design
Marketing your game
Appendix A: Scene navigation and keyboard shortcuts
A.1 Scene navigation using the mouse
A.2 Commonly used keyboard shortcuts
Appendix B: External tools used alongside Unity
B.1 Programming tools
B.1.1 Visual Studio
B.1.2 Xcode
B.1.3 Android SDK
B.1.4 SVN, Git, or Mercurial
B.2 3D art applications
B.2.1 Maya
B.2.2 3ds Max
B.2.3 Blender
B.2.4 SketchUp
B.3 2D image editors
B.3.1 Photoshop
B.3.2 GIMP
B.3.3 TexturePacker
B.3.4 Aseprite, Pyxel Edit
B.4 Audio software
B.4.1 Pro Tools
B.4.2 Audacity
Appendix C: Modeling a bench in Blender
Building the mesh geometry
Texture-mapping the model
Appendix D: Online learning resources
Additional tutorials
Code libraries
Index
List of Tables
Table 4.2: 2D image file formats supported by Unity
Table 4.3: 3D Model file formats supported by Unity
Table 8.1: Conditions for all transitions in this animation controller
Table 11.1: Audio file formats supported by Unity
Table A.1: Scene navigation controls for various kinds of mice
Table A.2: Useful keyboard shortcuts
Table 4.1: Types of art assets
List of Illustrations
Figure 1.1
Figure 1.2
Figure 1.3
Figure 1.4
Figure 1.5
Figure 1.6
Figure 1.7
Figure 1.8
Figure 1.9
Figure 1.10
Figure 1.11
Figure 1.12
Figure 1.13
Figure 1.14
Figure 1.15
Figure 1.16
Figure 2.1
Figure 2.2
Figure 2.3
Figure 2.4
Figure 2.5
Figure 2.6
Figure 2.7
Figure 2.8
Figure 2.9
Figure 2.10
Figure 2.11
Figure 2.12
Figure 2.13
Figure 2.14
Figure 2.15
Figure 3.1
Figure 3.2
Figure 3.3
Figure 3.4
Figure 3.5
Figure 3.6
Figure 3.7
Figure 3.8
Figure 3.9
Figure 3.10
Figure 3.11
Figure 3.12
Figure 4.1
Figure 4.2
Figure 4.3
Figure 4.4
Figure 4.5
Figure 4.6
Figure 4.7
Figure 4.8
Figure 4.9
Figure 4.10
Figure 4.11
Figure 4.12
Figure 4.13
Figure 4.14
Figure 4.15
Figure 4.16
Figure 4.17
Figure 4.18
Figure 4.19
Figure 4.20
Figure 4.21
Figure 4.22
Figure 4.23
Figure 5.1
Figure 5.2
Figure 5.3
Figure 5.4
Figure 5.5
Figure 5.6
Figure 5.7
Figure 5.8
Figure 5.9
Figure 5.10
Figure 5.11
Figure 6.1
Figure 6.2
Figure 6.3
Figure 6.4
Figure 6.5
Figure 6.6
Figure 6.7
Figure 6.8
Figure 6.9
Figure 6.10
Figure 6.11
Figure 7.1
Figure 7.2
Figure 7.3
Figure 7.4
Figure 7.5
Figure 7.6
Figure 7.7
Figure 7.8
Figure 7.9
Figure 7.10
Figure 7.11
Figure 7.12
Figure 7.13
Figure 7.14
Figure 7.15
Figure 7.16
Figure 7.17
Figure 8.1
Figure 8.2
Figure 8.3
Figure 8.4
Figure 8.5
Figure 8.6
Figure 8.7
Figure 8.8
Figure 8.9
Figure 8.10
Figure 8.11
Figure 8.12
Figure 8.13
Figure 8.14
Figure 8.15
Figure 8.16
Figure 8.17
Figure 8.18
Figure 9.1
Figure 9.2
Figure 9.3
Figure 9.4
Figure 9.5
Figure 9.6
Figure 9.7
Figure 9.8
Figure 9.9
Figure 10.1
Figure 10.2
Figure 10.3
Figure 10.4
Figure 10.5
Figure 10.6
Figure 10.7
Figure 11.1
Figure 11.2
Figure 11.3
Figure 11.4
Figure 11.5
Figure 12.1
Figure 12.2
Figure 12.3
Figure 12.4
Figure 12.5
Figure 12.6
Figure 12.7
Figure 12.8
Figure 12.9
Figure 13.1
Figure 13.2
Figure 13.3
Figure 13.4
Figure 13.5
Figure 13.6
Figure 13.7
Figure C.1
Figure C.2
Figure C.3
Figure C.4
Figure C.5
Figure C.6
Figure C.7
Figure C.8
Figure C.9
Figure C.10
Figure C.11
Figure C.12
Guide
Cover
Front Matter
foreword
preface
Part 1: First steps
Chapter 1: Getting to know Unity
Start Reading
Pages
i
iii
xv
xvi
xvii
xviii
xix
xx
xxi
xxii
xxiii
xxiv
xxv
xxvii
xxviii
1
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
101
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
Prev
Previous Chapter
Cover
Next
Next Chapter
Praise for the First Edition