Unity Game Development Essentials Build fully functional, professional 3D games with realistic environments, sound, dynamic effects, and more! Will Goldstone 1- PUBLISHING -J BIRMINGHAM - MUMBAI
Preface 1 Chapter 1: Welcome to the Third Dimension 9 Getting to grips with 3D 9 Coordinates 9 Local space versus World space 10 Vectors 10 Cameras 10 Polygons, edges, vertices, and meshes 11 Materials, textures, and shaders 12 Rigid Body physics 12 Collision detection 13 Essential Unity concepts 14 The Unity way 14 Assets 15 Scenes 15 Game Objects ^ 15 Components "" 15 Scripts 16 Prefabs 16 The interface 17 The Scene window and Hierarchy 18 The Inspector 18 The Project window 20 The Game window 20 Summary 21 Chapter 2: Environments 23 External modellers 23 Resources 24 Your first Unity project 24
Using the terrain editor 26 Terrain menu features 26 Importing and exporting heightmaps 26 Set Heightmap resolution 27 Creating the lightmap 28 Mass Place Trees 28 Flatten Heightmap 29 Refresh Tree and Detail Prototypes 29 The terrain toolset 29 Terrain Script 29 Raise Height 30 Paint height 31 Smooth height 32 Paint Texture ' 33 Place Trees 34 Paint Details 35 Terrain Settings 35 Sun, Sea, Sand creating the island 37 Take Me Home! Introducing models 57 Importing the model package 58 Common settings for models 59 Setting up the outpost model 61 Summary 63 Chapter 3: Player Characters 65 Working with the Inspector 66 Tags 66 Layers 68 Prefabs and the Inspector 68 Deconstructing the First Person Controller object 69 Parent-child issues 70 First Person Controller objects 70 Object 1: First Person Controller (parent) 72 Object 2: Graphics 76 Object 3: Main Camera 77 Scripting basics 81 Commands 81 Variables 82 Functions 84 If else statements 86 Globals and dot syntax 88 Comments 89 Further reading 89 The FPSWalker script 89 Launching the script 89 Deconstructing the script 91 Summary 97 [M]
Chapter 4: Interactions 99 Exploring collisions 100 Ray casting 101 The frame miss 102 Predictive collision detection 102 Adding the outpost 103 Positioning 104 Scaling, 105 Colliders and tagging the door 106 Disabling automatic animation 109 Opening the outpost, 110 Approach 1 Collision detection 110 Creating new assets 110 Scripting for character collision detection 111 Attaching the script 120 Approach 2 Ray casting 123 Disabling collision detection using comments 124 Resetting the door collider 124 Adding the ray 125 Summary 126 Chapter 5: Prefabs, Collection, and HUD 127 Creating the battery prefab 128 Download, import, and place 128 Tagging the battery 129 Scale, collider, and rotation 129 Enlarging the battery 129 Adding a trigger collider 130 Creating a rotation effect 130 Saving as a prefab 131 Scattering batteries 131 Displaying the battery GUI 132 Creating the GUI Texture object 133 Positioning the GUI Texture 134 Scripting for GUI change 135 Battery collection with triggers 139 Restricting outpost access 141 Restricting access 142 Utilizing GetComponentO 143 Hints for the player 144 Battery GUI hint 144 GUI Text hint 144 Using fonts 148 Summary 150 [Hi]
Chapter 6: Instantiation and Rigid Bodies 151 Introducing instantiation 152 In concept 152 In code 152 Passing in an object 153 Position and rotation 153 Introducing rigid bodies 154 Forces 154 The Rigidbody component 154 Making the minigame 155 Creating the coconut prefab 156 Creating the textured coconut 156 Adding physics 158 Saving as a prefab 158 Creating the Launcher object 158 Scripting coconut throws 161 Checking for player input 162 Playing feedback sound 162 Instantiating the coconut. 163 Naming instances 163 Assigning velocity 164 Safeguarding collisions 165 Script and variable assignment 166 Instantiate restriction and object tidying 167 Activating coconut throw 168 Removing coconuts 170 Adding the coconut shy platform 171 Import settings 171 Placement 173 Coconut detection script 174 Script assignment 176 Making more targets ^" 178 Winning the game 178 Variable setup 178 Checking for a win 179 Script assignment 180 Incrementing and decrementing targets 180 Finishing touches 181 Adding the crosshair 181 Informing the player 182 Summary 184 Chapter 7: Particle Systems 185 What is a particle system? 185 Particle emitter 186 Particle Animator 187 [iv]
Particle Renderer 187 In summary 188 Making the task 188 Asset download 189 Adding the log pile 189 Creating the fire particle systems 191 Making fire 191 Making smoke 196 Adding audio to the fire 199 Lighting the fire 199 Adding the matches 200 Creating the Matches GUI 200 Collecting the matches 200 Setting fire 202 Testing and confirming 204 Summary 205 Chapter 8: Menu Design 207 Interfaces and menus 208 Making the main menu 209 Creating the scene 209 Cancelling mip mapping 211 Adding titling 212 Creating the menu approach 1 213 Adding the play button 214 GUI Texture button script 214 Assigning public member variables 216 Adding the instructions button 217 Adding the quit button 218 Using debug commands to check scripts 220 Creating the menu approach 2 221 Disabling Game Objects - ^ 221 Writing an OnGUI() script for a simple menu 221 Fixed versus layout 221 Public member variables 222 The OnGUI() function 222 Flexible positioning for GUIs 222 Adding UnityGUI buttons 224 Opening scenes with custom functions 225 GUI skin settings 227 Decision time 230 Summary 231 Chapter 9: Finishing Touches 233 Volcano! 234 Positioning the particle system 234 [V]
Table of Con ten ts Downloading assets 236 Making the smoke material 237 Particle system settings 237 Ellipsoid Particle Emitter settings 238 Particle Animator settings 238 Adding audio to the volcano 239 Volcano testing 240 Coconut trails 240 Editing the Prefab 240 Trail Renderer component 241 Updating the prefab 243 Performance tweaks 243 Camera Clip Planes and fog 244 Ambient lighting 245 Instructions scene 245 Adding screen text 245 Text Animation using Linear Interpolation (Lerp) 246 Menu return 249 Island level fade-in 252 UnityGUI texture rendering 254 Game win notification 255 Summary 256 Chapter 10: Building and Sharing 257 Build Settings 258 Web Player 259 Player Settings 259 Web Player Streamed 261 OS X Dashboard Widget 261 OS X/Windows Standalone 262 Building the game 263 Adapting for web build 263 Texture compression and debug stripping 266 Building standalone 266 Indie versus Pro 268 Building for the Web 269 Adapting web player builds 269 Quality Settings 270 Player Input settings 273 Sharing your work 275 Summary 276 [vi]
Chapter 11: Testing and Further Study 277 Testing and finalizing 278 Public testing 278 Frame rate feedback 279 Boosting performance 282 Approaches to learning 282 Cover as many bases as possible 282 If you don't know, just ask! 283 Summary 284 Index 285 [vii]