PART 1FIRST STEPS ..................................... 1
1 Getting to know Unity
1.1 Why is Unity so great?
Unity's strengths and advantages
Downsides to be aware of
Example games built with Unity
1.2 How to use Unity
Scene view, Game view, and the Toolbar
Using the mouse and keyboard
The Hierarchy tab and the Inspector
The Project and Console tabs
1.3 Getting up and running with Unity programming
How code runs in Unity: script components
Using MonoDevelop, the cross-platform IDE
Printing to the console: Hello World!
1.4 Summary
2 Building a demo that puts you in 3D space
2.1 Before you start…
Planning the project
Understanding 3D coordinate space
2.2 Begin the project: place objects in the scene
The scenery: floor, outer walls, inner walls
Lights and cameras
The player’s collider and viewpoint
2.3 Making things move: a script that applies transforms
Diagramming how movement is programmed
Writing code to implement the diagram
Local vs. global coordinate space
2.4 Script component for looking around: MouseLook
Horizontal rotation that tracks mouse movement
Vertical rotation with limits
Horizontal and vertical rotation at the same time
2.5 Keyboard input component: first-person controls
Responding to key presses
Setting a rate of movement independent of the computer’s speed
Moving the CharacterController for collision detection
Adjusting components for walking instead of flying
2.6 Summary
3 Adding enemies and projectiles to the 3D game
3.1 Shooting via raycasts
What is raycasting?
Using the command ScreenPointToRay for shooting
Adding visual indicators for aiming and hits
3.2 Scripting reactive targets
Determining what was hit
Alert the target that it was hit
3.3 Basic wandering AI
Diagramming how basic AI works
“Seeing” obstacles with a raycast
Tracking the character’s state
3.4 Spawning enemy prefabs
What is a prefab?
Creating the enemy prefab
Instantiating from an invisible SceneController
3.5 Shooting via instantiating objects
Creating the projectile prefab
Shooting the projectile and colliding with a target
Damaging the player
3.6 Summary
4 Developing graphics for your game
4.1 Understanding art assets
4.2 Building basic 3D scenery: whiteboxing
Whiteboxing explained
Drawing a floor plan for the level
Laying out primitives according to the plan
4.3 Texture the scene with 2D images
Choosing a file format
Importing an image file
Applying the image
4.4 Generating sky visuals using texture images
What is a skybox?
Creating a new skybox material
4.5 Working with custom 3D models
Which file format to choose?
Exporting and importing the model
4.6 Creating effects using particle systems
Adjusting parameters on the default effect
Applying a new texture for fire
Attaching particle effects to 3D objects
4.7 Summary
PART 2GETTING COMFORTABLE ................................ 93
5 Building a Memory game using Unity’s new 2D functionality
5.1 Setting everything up for 2D graphics
Preparing the project
Displaying 2D images (akasprites)
Switching the camera to 2D mode
5.2 Building a card object and making it react to clicks
Building the object out of sprites
Mouse input code
Revealing the card on click
5.3 Displaying the various card images
Loading images programmatically
Setting the image from an invisible SceneController
Instantiating a grid of cards
Shuffling the cards
5.4 Making and scoring matches
Storing and comparing revealed cards
Hiding mismatched cards
Text display for the score
5.5 Restart button
Programming a UIButton component using SendMessage
Calling LoadLevel from SceneController
5.6 Summary
6 Putting a 2D GUI in a 3D game
6.1 Before you start writing code…
Immediate mode GUI or advanced 2D interface?
Planning the layout
Importing UI images
6.2 Setting up the GUI display
Creating a canvas for the interface
Buttons, images, and text labels
Controlling the position of UI elements
6.3 Programming interactivity in the UI
Programming an invisible UIController
Creating a pop-up window
Setting values using sliders and input fields
6.4 Updating the game by responding to events
Integrating an event system
Broadcasting and listening for events from the scene
Broadcasting and listening for events from the HUD
6.5 Summary
7 Creating a third-person 3D game: player movement and animation
7.1 Adjusting the camera view for third-person
Importing a character to look at
Adding shadows to the scene
Orbiting the camera around the player character
7.2 Programming camera-relative movement controls
Rotating the character to face movement direction
Moving forward in that direction
7.3 Implementing the jump action
Applying vertical speed and acceleration
Modifying the ground detection to handle edges and slopes
7.4 Setting up animations on the player character
Defining animation clips in the imported model
Creating the animator controller for these animations
Writing code that operates the animator
7.5 Summary
8 Adding interactive devices and items within the game
8.1 Creating doors and other devices
Doors that open and close on a keypress
Checking distance and facing before opening the door
Operating a color-changing monitor
8.2 Interacting with objects by bumping into them
Colliding with physics-enabled obstacles
Triggering the door with a pressure plate
Collecting items scattered around the level
8.3 Managing inventory data and game state
Setting up player and inventory managers
Programming the game managers
Storing inventory in a collection object: List vs. Dictionary
8.4 Inventory UI for using and equipping items
Displaying inventory items in the UI
Equipping a key to use on locked doors
Restoring the player’s health by consuming health packs
8.5 Summary
PART 3STRONG FINISH ........................................... 193
9 Connecting your game to the internet
9.1 Creating an outdoor scene
Generating sky visuals using a skybox
Setting up an atmosphere that’s controlled by code
9.2 Downloading weather data from an internet service
Requesting WWW data using coroutines
Parsing XML 207
Parsing JSON
Affecting the scene based on Weather Data
9.3 Adding a networked billboard
Loading images from the internet
Displaying images on the billboard
Caching the downloaded image for reuse
9.4 Posting data to a web server
Tracking current weather: sending post requests
Serverside code in PHP
9.5 Summary
10 Playing audio: sound effects and music
10.1 Importing sound effects
Supported file formats
Importing audio files
10.2 Playing sound effects
Explaining what’s involved: audio clip vs. source vs. listener
Assigning a looping sound
Triggering sound effects from code
10.3 Audio control interface
Setting up the central AudioManager
Volume control UI
Playing UI sounds
10.4 Background music
Playing music loops
Controlling music volume separately
Fading between songs
10.5 Summary
11 Putting the parts together into a complete game
11.1 Building an action RPG by repurposing projects
Assembling assets and code from multiple projects
Programming point-and-click controls: movement and devices
Replacing the old GUI with a new interface
11.2 Developing the overarching game structure
Controlling mission flow and multiple levels
Completing a level by reaching the exit
Losing the level when caught by enemies
11.3 Handling the player’s progression through the game
Saving and loading the player’s progress
Beating the game by completing three levels
11.4 Summary
12 Deploying your game to players’ devices
12.1 Start by building for the desktop: Windows, Mac, and Linux
Building the application
Adjusting Player Settings: setting the game’s name and icon
Platform-dependent compilation
12.2 Building for the web
Unity Player vs. HTML5/WebGL
Building the Unity file and a test web page
Communicating with JavaScript in the browser
12.3 Building for mobile apps: iOS and Android
Setting up the build tools
Texture compression
Developing plug-ins
12.4 Summary