Unity 3.x Game Development Essentials: Game Development with C# and Javascript 1849691444, 9781849691444

Annotation Game Engines such as Unity are the power-tools behind the games we know and love. Unity is one of the most wi

118 60 11MB

English Pages 462 [488] Year 2011

Report DMCA / Copyright

DOWNLOAD FILE

Unity 3.x Game Development Essentials: Game Development with C# and Javascript
 1849691444, 9781849691444

Table of contents :
Cover
Copyright
Credits
Foreword
About the Author
About the Reviewers
www.PacktPub.com
Table of Contents
Preface
Chapter 1: Enter the Third Dimension
Getting to grips with 3D
Coordinates
Local space versus world space
Vectors
Cameras
Projection mode—3D versus 2D
Polygons, edges, vertices, and meshes
Materials, textures, and shaders
Rigidbody physics
Collision detection
Essential Unity concepts
The Unity way—an example
Assets
Scenes
GameObjects
Components
Scripts
Prefabs
The interface
The Scene view and Hierarchy
Control tools
Flythrough Scene navigation
Control bar
Search box
Create button
The Inspector
The Project window
The Game view
Summary
Chapter 2: Prototyping and Scripting Basics
Your first Unity project
A basic prototyping environment
Setting the scene
Adding simple lighting
Another brick in the wall
Building the master brick
And snap!—It's a row
Grouping and duplicating with empty objects
Build it up, knock it down!
Setting the viewpoint
Introducing scripting
A new behaviour script or 'class'
What's inside a new C# behaviour
Basic functions
Variables in C#
What's inside a new Javascript behaviour
Variables in Javascript
Comments
Wall attack
Declaring public variables
Assigning scripts to objects
Moving the camera
Local, private, and public variables
Understanding Translate
Implementing Translate
Testing the game so far
Making a projectile
Creating the projectile prefab
Creating and applying a material
Adding physics with a Rigidbody
Storing with prefabs
Firing the projectile
Using Instantiate() to spawn objects
Adding a force to the Rigidbody
Summary
Chapter 3: Creating the Environment
Designing the game
Using the terrain editor
Terrain menu features
Importing and exporting heightmaps
Setting the resolution
Mass place trees
Flatten Heightmap
Refresh tree and detail prototypes
The terrain toolset
Terrain Script
Raise height
Paint height
Smooth Height
Paint Texture
Place Trees
Paint Details
Terrain Settings
Creating the island—sun, sea, and sand
Step 1—Setting up the terrain
Step 2—Creating the Island outline
Step 3—Volcano!
Step 4—Adding textures
Step 5—Tree time
Step 6—The grass is always greener
Step 7—Let there be lights!
Step 8—What's that sound?
Step 9—Look, there! Up in the skybox!
Step 10—Open water
Step 11—Going walkabout
Step 12—Final tweaks
Summary
Chapter 4: Player Characters and Further Scripting
Working with the Inspector
Tags
Layers
Prefabs and the Inspector
Anatomy of a character
Deconstructing the First Person Controller object
Parent-child issues
First Person Controller object
Object 1: First Person Controller (parent)
Object 2: Graphics (child)
Object 3: Main Camera (child)
Further scripting
Commands
Variables
Variable data types
Using variables
Full example
Functions
Update()
OnMouseDown()
Writing custom functions
Return type
Arguments
Declaring a custom function
Calling a custom function
If else statements
Multiple conditions
For loops
Inter-script communication and Dot Syntax
Accessing other objects
Find() and FindWithTag()
SendMessage
GetComponent
Comments
Further reading
Scripting for character movement
Deconstructing the script
Full script (Javascript)
Variable declaration
Storing movement information
Moving the character
Checking grounded
@Script commands
Summary
Chapter 5: Interactions
External modeling applications
Common settings for models
Meshes
Normals and Tangents
Materials
Animations
Animation Compression
Setting up the outpost model
Adding the outpost
Positioning
Rotation
Adding colliders
Adding the Rigidbody
Adding audio
Disabling automatic animation
Collisions and triggers
Ray casting
The frame miss
Predictive collision detection
Opening the outpost
Approach 1—Collision detection
Creating new assets
Scripting for character collision detection
Approach 2—Ray casting
Disabling collision detection with comments
Migrating code—writing a DoorManager script
Tidying PlayerCollisions
Casting the ray
Resetting the collider
Approach 3—Trigger collision detection
Creating and scaling the trigger zone
Scripting for trigger collisions
Summary
Chapter 6: Collection, Inventory, and HUD
Creating the power cell prefab
Downloading, importing, and placing
Tagging the power cell
Collider scaling and rotation
Enlarging the power cell
Adding a trigger collider
Collider scale
Adding the Rigidbody
Creating the power cell script
Adding rotation
Adding Trigger Collision Detection
Saving as a prefab
Scattering power cells
Writing the Player Inventory
Saving the charge value
Setting the variable start value
Audio feedback
Adding the CellPickup() function
Adding the Inventory to the player
Restricting outpost access
Restricting door access with a cell counter
Displaying the power cell HUD
Import settings for GUI textures
Creating the GUITexture object
Positioning the PowerGUI texture
Scripting for texture swap
Understanding arrays
Adding the HUD array
Assigning textures to the array
Disabling the HUD for game start
Enabling the HUD during runtime
Adding the power generator
Signifying door unlock
Adding the locked light
Switching lights and removing the HUD
Hints for the player
Writing on screen with GUIText
Scripting for GUIText control
Adjusting hints to show progress
Using fonts
Summary
Chapter 7: Instantiation and Rigidbodies
Utilizing instantiation
Rigidbodies
Forces
The Rigidbody component
Making the mini-game
Creating the coconut prefab
Creating the textured coconut
Adding physics
Saving as a prefab
Creating the Launcher object
Scripting to throw coconuts
Checking for player input
Playing feedback sound
Instantiating the coconut
Naming instances
Assigning velocity
Adding development safeguards
Final checks
Instantiate restriction and object tidying
Activating coconut throw
Adding the coconut shy shack
Import settings
Removing coconuts
Placement
Disabling automatic animation
Adding Rigidbodies to moving parts
Writing the Coconut collision detection script
Assigning the script
Creating more targets
Winning the game
Setting up variables
Checking for a win
Script assignment
Incrementing and decrementing target count
Finishing touches
Adding the crosshair
Informing the player
Summary
Chapter 8: Particle Systems
What is a particle system?
Particle Emitter
Particle Animator
Particle Renderer
Creating the task
Assets involved
Adding the log pile
Creating the campfire particle systems
Creating fire
Blowing smoke!
Adding audio to the fire
Lighting the fire
Adding the matches
Creating the matches GUI
Collecting the matches
Starting the fire
Testing and confirming
So, what's the problem?
Safeguarding with additional conditions
Summary
Chapter 9: Designing Menus
Interfaces and menus
Creating the scene
Duplicating the island
Preparing textures for GUI usage
Adding the game title
Creating the menu with GUITextures and mouse events
Adding the play button
GUITexture button script
Loading scenes
Assigning public variables
Testing the button
Adding the instructions button
Adding the quit button
Checking scripts with Debug commands
Creating the menu with the Unity GUI class and GUI skins
Disabling game objects
Creating the menu
Creating public variables
The OnGUI() function
Positioning for GUIs
Styling GUI buttons with a GUI skin
Using textures for GUI button backgrounds
Choosing font size for GUI buttons
Scripting button actions
Adding the Instructions page
Summary
Chapter 10: Animation Basics
Game win sequence
Win sequence approach
Triggering the win
Creating the game win messages
Positioning win sequence GUI elements
Grouping GUITextures for optimized instantiation
Animating with linear interpolation (Lerp)
Adjusting animations
Storing the win sequence
Creating the win object
Creating the Fader and using the Animation panel
Scaling for various resolutions
Starting the Fader from invisibility
Animation panel overview
Creating an animation clip
Creating keyframes
Using animation curves
Adding animation events
Creating and animating the Loading GUI
Loading scenes with animation events
Storing and instantiating the Loading GUI
Loading the win sequence
Layering GUITextures
Challenge—fading in the Island scene
Summary
Chapter 11: Performance Tweaks and Finishing Touches
Terrain tweaks and player position
Tweaking the terrain
Positioning trees
Hills, troughs, and texture blending
Life's a beach
Keep on the right path
Positioning the player
Optimizing performance
Camera Clip Planes and Fog
Lightmapping
Lighting and baking the island
Preparing for lightmapping
Baking the lightmap
Restoring dynamic objects
Finishing touches
Volcano!
Positioning the particle system
Making the smoke material
Particle system settings
Adding audio to the volcano
Volcano testing
Coconut trails
Editing the Prefab
Trail Renderer component
Updating the prefab
Summary
Chapter 12: Building and Sharing
Build options
Web Player
Web Player Streamed
PC or Mac standalone
OSX Dashboard Widget
Build Settings
Player Settings
Cross-Platform Settings
Per-Platform Settings
Quality Settings
Player Input settings
Building the game
Adapting for web build
Quit button platform automation
Preparing for streaming
First Build
Building the Standalone
Free versus Pro
Building for the Web
Embedding web player builds in your own site
Sharing your work
Sharing on Kongregate.com
Summary
Chapter 13: Testing and Further Study
Learn by doing
Testing and finalizing
Public testing
Frame rate feedback
Optimizing performance
Approaches to learning
Cover as many bases as possible
Don't reinvent the wheel
If you don't know, just ask!
Summary

Polecaj historie