资源说明:Table of Contents
Preface 1
Chapter 1: Enter the Third Dimension 7
Getting to grips with 3D 7
Coordinates 8
Local space versus world space 9
Vectors 11
Cameras 11
Projection mode—3D versus 2D 11
Polygons, edges, vertices, and meshes 12
Materials, textures, and shaders 14
Rigidbody physics 15
Collision detection 16
Essential Unity concepts 17
The Unity way—an example 18
Assets 19
Scenes 19
GameObjects 19
Components 20
Scripts 20
Prefabs 21
The interface 22
The Scene view and Hierarchy 23
Control tools 23
Flythrough Scene navigation 24
Control bar 24
Search box 25
Create button 25
The Inspector 25
The Project window 26
Table of Contents
[ ii ]
The Game view 27
Summary 28
Chapter 2: Prototyping and Scripting Basics 29
Your first Unity project 29
A basic prototyping environment 31
Setting the scene 32
Adding simple lighting 33
Another brick in the wall 34
Building the master brick 34
And snap!—It's a row 36
Grouping and duplicating with empty objects 38
Build it up, knock it down! 39
Setting the viewpoint 39
Introducing scripting 39
A new behaviour script or 'class' 40
What's inside a new C# behaviour 41
Basic functions 42
Variables in C# 42
What's inside a new Javascript behaviour 43
Variables in Javascript 43
Comments 44
Wall attack 44
Declaring public variables 45
Assigning scripts to objects 46
Moving the camera 47
Local, private, and public variables 49
Understanding Translate 50
Implementing Translate 51
Testing the game so far 52
Making a projectile 53
Creating the projectile prefab 53
Creating and applying a material 54
Adding physics with a Rigidbody 55
Storing with prefabs 55
Firing the projectile 56
Using Instantiate() to spawn objects 56
Adding a force to the Rigidbody 57
Summary 59
Chapter 3: Creating the Environment 61
Designing the game 61
Using the terrain editor 63
Terrain menu features 64
Importing and exporting heightmaps 64
Table of Contents
[ iii ]
Setting the resolution 64
Mass place trees 66
Flatten Heightmap 66
Refresh tree and detail prototypes 66
The terrain toolset 66
Terrain Script 66
Raise height 67
Paint height 68
Smooth Height 69
Paint Texture 70
Place Trees 70
Paint Details 71
Terrain Settings 71
Creating the island—sun, sea, and sand 72
Step 1—Setting up the terrain 72
Step 2—Creating the Island outline 73
Step 3—Volcano! 74
Step 4—Adding textures 76
Step 5—Tree time 80
Step 6—The grass is always greener 81
Step 7—Let there be lights! 83
Step 8—What's that sound? 84
Step 9—Look, there! Up in the skybox! 87
Step 10—Open water 88
Step 11—Going walkabout 88
Step 12—Final tweaks 90
Summary 91
Chapter 4: Player Characters and Further Scripting 93
Working with the Inspector 94
Tags 95
Layers 96
Prefabs and the Inspector 97
Anatomy of a character 97
Deconstructing the First Person Controller object 99
Parent-child issues 99
First Person Controller object 100
Object 1: First Person Controller (parent) 100
Object 2: Graphics (child) 105
Object 3: Main Camera (child) 106
Further scripting 109
Commands 110
Variables 111
Variable data types 111
Using variables 112
Full example 114
Functions 115
Table of Contents
[ iv ]
Update() 115
OnMouseDown() 116
Writing custom functions 116
Return type 116
Arguments 117
Declaring a custom function 118
Calling a custom function 119
If else statements 121
Multiple conditions 123
For loops 124
Inter-script communication and Dot Syntax 125
Accessing other objects 125
Find() and FindWithTag() 126
SendMessage 126
GetComponent 127
Comments 130
Further reading 131
Scripting for character movement 131
Deconstructing the script 131
Full script (Javascript) 131
Variable declaration 132
Storing movement information 133
Moving the character 135
Checking grounded 136
@Script commands 137
Summary 137
Chapter 5: Interactions 139
External modeling applications 139
Common settings for models 140
Meshes 140
Normals and Tangents 141
Materials 142
Animations 142
Animation Compression 142
Setting up the outpost model 143
Adding the outpost 144
Positioning 144
Rotation 145
Adding colliders 145
Adding the Rigidbody 148
Adding audio 148
Disabling automatic animation 149
Table of Contents
[ v ]
Collisions and triggers 150
Ray casting 153
The frame miss 153
Predictive collision detection 154
Opening the outpost 156
Approach 1—Collision detection 156
Creating new assets 156
Scripting for character collision detection 157
Approach 2—Ray casting 172
Disabling collision detection with comments 172
Migrating code—writing a DoorManager script 173
Tidying PlayerCollisions 175
Casting the ray 176
Resetting the collider 178
Approach 3—Trigger collision detection 179
Creating and scaling the trigger zone 179
Scripting for trigger collisions 182
Summary 184
Chapter 6: Collection, Inventory, and HUD 185
Creating the power cell prefab 187
Downloading, importing, and placing 188
Tagging the power cell 188
Collider scaling and rotation 189
Enlarging the power cell 189
Adding a trigger collider 189
Collider scale 189
Adding the Rigidbody 190
Creating the power cell script 190
Adding rotation 191
Adding Trigger Collision Detection 192
Saving as a prefab 193
Scattering power cells 193
Writing the Player Inventory 195
Saving the charge value 195
Setting the variable start value 196
Audio feedback 196
Adding the CellPickup() function 196
Adding the Inventory to the player 197
Restricting outpost access 198
Restricting door access with a cell counter 199
Displaying the power cell HUD 200
Import settings for GUI textures 201
Creating the GUITexture object 201
Positioning the PowerGUI texture 202
Table of Contents
[ vi ]
Scripting for texture swap 203
Understanding arrays 203
Adding the HUD array 205
Assigning textures to the array 206
Disabling the HUD for game start 207
Enabling the HUD during runtime 208
Adding the power generator 210
Signifying door unlock 214
Adding the locked light 214
Switching lights and removing the HUD 215
Hints for the player 217
Writing on screen with GUIText 217
Scripting for GUIText control 218
Adjusting hints to show progress 221
Using fonts 222
Summary 224
Chapter 7: Instantiation and Rigidbodies 225
Utilizing instantiation 226
Rigidbodies 227
Forces 227
The Rigidbody component 228
Making the mini-game 229
Creating the coconut prefab 230
Creating the textured coconut 230
Adding physics 231
Saving as a prefab 231
Creating the Launcher object 232
Scripting to throw coconuts 234
Checking for player input 236
Playing feedback sound 236
Instantiating the coconut 237
Naming instances 238
Assigning velocity 239
Adding development safeguards 240
Final checks 245
Instantiate restriction and object tidying 246
Activating coconut throw 247
Adding the coconut shy shack 250
Import settings 250
Removing coconuts 252
Placement 256
Disabling automatic animation 256
Adding Rigidbodies to moving parts 257
Writing the Coconut collision detection script 257
Assigning the script 264
Creating more targets 265
Table of Contents
[ vii ]
Winning the game 266
Setting up variables 266
Checking for a win 267
Script assignment 269
Incrementing and decrementing target count 269
Finishing touches 271
Adding the crosshair 271
Informing the player 272
Summary 275
Chapter 8: Particle Systems 277
What is a particle system? 277
Particle Emitter 278
Particle Animator 278
Particle Renderer 279
Creating the task 280
Assets involved 280
Adding the log pile 281
Creating the campfire particle systems 283
Creating fire 283
Blowing smoke! 288
Adding audio to the fire 291
Lighting the fire 293
Adding the matches 293
Creating the matches GUI 296
Collecting the matches 296
Starting the fire 299
Testing and confirming 304
So, what's the problem? 304
Safeguarding with additional conditions 305
Summary 306
Chapter 9: Designing Menus 307
Interfaces and menus 308
Creating the scene 310
Duplicating the island 310
Preparing textures for GUI usage 312
Adding the game title 313
Creating the menu with GUITextures and mouse events 315
Adding the play button 315
GUITexture button script 315
Loading scenes 318
Assigning public variables 319
Testing the button 319
Adding the instructions button 320
Table of Contents
[ viii ]
Adding the quit button 321
Checking scripts with Debug commands 324
Creating the menu with the Unity GUI class and GUI skins 325
Disabling game objects 326
Creating the menu 326
Creating public variables 327
The OnGUI() function 328
Positioning for GUIs 328
Styling GUI buttons with a GUI skin 332
Using textures for GUI button backgrounds 333
Choosing font size for GUI buttons 335
Scripting button actions 340
Adding the Instructions page 344
Summary 350
Chapter 10: Animation Basics 351
Game win sequence 351
Win sequence approach 353
Triggering the win 354
Creating the game win messages 354
Positioning win sequence GUI elements 355
Grouping GUITextures for optimized instantiation 355
Animating with linear interpolation (Lerp) 355
Adjusting animations 358
Storing the win sequence 358
Creating the win object 358
Creating the Fader and using the Animation panel 360
Scaling for various resolutions 361
Starting the Fader from invisibility 362
Animation panel overview 363
Creating an animation clip 364
Creating keyframes 364
Using animation curves 367
Adding animation events 368
Creating and animating the Loading GUI 370
Loading scenes with animation events 372
Storing and instantiating the Loading GUI 373
Loading the win sequence 373
Layering GUITextures 375
Challenge—fading in the Island scene 375
Summary 376
Chapter 11: Performance Tweaks and Finishing Touches 377
Terrain tweaks and player position 378
Tweaking the terrain 378
Positioning trees 378
Table of Contents
[ ix ]
Hills, troughs, and texture blending 379
Life's a beach 380
Keep on the right path 380
Positioning the player 382
Optimizing performance 382
Camera Clip Planes and Fog 383
Lightmapping 384
Lighting and baking the island 384
Preparing for lightmapping 384
Baking the lightmap 389
Restoring dynamic objects 394
Finishing touches 394
Volcano! 394
Positioning the particle system 395
Making the smoke material 397
Particle system settings 397
Adding audio to the volcano 398
Volcano testing 399
Coconut trails 400
Editing the Prefab 400
Trail Renderer component 401
Updating the prefab 402
Summary 404
Chapter 12: Building and Sharing 405
Build options 406
Web Player 407
Web Player Streamed 407
PC or Mac standalone 408
OSX Dashboard Widget 408
Build Settings 409
Player Settings 410
Cross-Platform Settings 410
Per-Platform Settings 411
Quality Settings 415
Player Input settings 418
Building the game 419
Adapting for web build 419
Quit button platform automation 419
Preparing for streaming 421
First Build 427
Building the Standalone 427
Free versus Pro 428
Building for the Web 429
Embedding web player builds in your own site 430
Table of Contents
[ x ]
Sharing your work 434
Sharing on Kongregate.com 434
Summary 435
Chapter 13: Testing and Further Study 437
Learn by doing 438
Testing and finalizing 438
Public testing 439
Frame rate feedback 439
Optimizing performance 442
Approaches to learning 443
Cover as many bases as possible 443
Don't reinvent the wheel 444
If you don't know, just ask! 444
Summary 445
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。