Unity in Action
Multiplatform game development in C# with Unity 5
Joseph Hocking
Foreword by Jesse Schell
  • June 2015
  • ISBN 9781617292323
  • 352 pages
  • printed in black & white

Joe Hocking wastes none of your time and gets you coding fast.

From the Foreword by Jesse Schell, Author of "The Art of Design"

Unity in Action teaches you how to write and deploy games. You’ll master the Unity toolset from the ground up, adding the skills you need to go from application coder to game developer. Based on Unity version 5.

Table of Contents show full




about this book

Part 1 First steps

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 tab and the Inspector

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!

1.4. Summary

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 cooordinate space

2.2. Begin the project: place objects in the scene

2.2.1. The scenery: floor, outer walls, 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. Diagramming 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 key presses

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

2.6. Summary

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 command ScreenPointToRay 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. Instantiatiing from an invisible SceneController

3.5. Shooting via 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

3.6. Summary

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

4.7. Summary

Part 2 Getting comfortable

5. Building a Memory game using Unity’s new 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 LoadLevel from SceneController

5.6. Summary

6. Putting a 2D GUI in a 3D game

6.1. Before you start writing code…​

6.1.1. Immediate mode GUI or advanced 2D interface?

6.1.2. Planning the layout

6.1.3. Importing UI images

6.2. Setting up the GUI display

6.2.1. Creating a canvas for the interface

6.2.2. Buttons, images, and text labels

6.2.3. Controlling the position of UI elements

6.3. Programming interactivity in the UI

6.3.1. Programming an invisible UIController

6.3.2. Creating a pop-up window

6.3.3. Setting values using sliders and input fields

6.4. Updating the game by responding to events

6.4.1. Integrating an event system

6.4.2. Broadcasting and listening for events from the scene

6.4.3. 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

7.1.1. Importing a character to look at

7.1.2. Adding shadows to the scene

7.1.3. Orbiting the camera around the player character

7.2. Programming camera-relative movement controls

7.2.1. Rotating the character to face movement direction

7.2.2. Moving forward in that direction

7.3. Implementing the jump action

7.3.1. Applying vertical speed and acceleration

7.3.2. Modifying the ground detection to handle edges and slopes

7.4. Setting up animations on the player character

7.4.1. Defining animation clips in the imported model

7.4.2. Creating the animator controller for these animations

7.4.3. 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

8.1.1. Doors that open and close on a keypress

8.1.2. Checking distance and facing before opening the door

8.1.3. Operating a color-changing monitor

8.2. Interacting with objects by bumping into them

8.2.1. Colliding with physics-enabled obstacles

8.2.2. Triggering the door with a pressure plate

8.2.3. Collecting items scattered around the level

8.3. Managing inventory data and game state

8.3.1. Setting up player and inventory managers

8.3.2. Programming the game managers

8.3.3. Storing inventory in a collection object: List vs. Dictionary

8.4. Inventory UI for using and equipping items

8.4.1. Displaying inventory items in the UI

8.4.2. Equipping a key to use on locked doors

8.4.3. Restoring the player’s health by consuming health packs

8.5. Summary

Part 3 Strong finish

9. Connecting your game to the internet

9.1. Creating an outdoor scene

9.1.1. Generating sky visuals using a skybox

9.1.2. Setting up an atmosphere that’s controlled by code

9.2. Downloading weather data from an internet service

9.2.1. Requesting WWW data using coroutines

9.2.2. Parsing XML

9.2.3. Parsing JSON

9.2.4. Affecting the scene based on Weather Data

9.3. Adding a networked billboard

9.3.1. Loading images from the internet

9.3.2. Displaying images on the billboard

9.3.3. Caching the downloaded image for reuse

9.4. Posting data to a web server

9.4.1. Tracking current weather: sending post requests

9.4.2. Serve-side code in PHP

9.5. Summary

10. Playing audio: sound effects and music

10.1. Importing sound effects

10.1.1. Supported file formats

10.1.2. Importing audio files

10.2. Playing sound effects

10.2.1. Explaining what’s involved: audio clip vs. source vs. listener

10.2.2. Assigning a looping sound

10.2.3. Triggering sound effects from code

10.3. Audio control interface

10.3.1. Setting up the central AudioManager

10.3.2. Volume control UI

10.3.3. Playing UI sounds

10.4. Background music

10.4.1. Playing music loops

10.4.2. Controlling music volume separately

10.4.3. Fading between songs

10.5. Summary

11. Putting the parts together into a complete game

11.1. Building an action RPG by repurposing projects

11.1.1. Assembling assets and code from multiple projects

11.1.2. Programming point-and-click controls: movement and devices

11.1.3. Replacing the old GUI with a new interface

11.2. Developing the overarching game structure

11.2.1. Controlling mission flow and multiple levels

11.2.2. Completing a level by reaching the exit

11.2.3. Losing the level when caught by enemies

11.3. Handling the player’s progression through the game

11.3.1. Saving and loading the player’s progress

11.3.2. 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

12.1.1. Building the application

12.1.2. Adjusting Player Settings: setting the game’s name and icon

12.1.3. Platform-dependent compilation

12.2. Building for the web

12.2.1. Unity Players vs. HTML5/WebGL

12.2.2. Building the Unity file and a test web page

12.2.3. Communicating with JavaScript in the browser

12.3. Building for mobile apps: iOS and Android

12.3.1. Setting up the build tools

12.3.2. Texture compression

12.3.3. Developing plug-ins

12.4. Summary



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.3. 2D image editors

B.3.1. Photoshop

B.3.2. GIMP

B.3.3. TexturePacker

B.4. Audio software

B.4.1. Pro Tools

B.4.2. Audacity

Appendix C: Modeling a bench in Blender

C.1. Building the mesh geometry

C.2. Texture-mapping the model

Appendix D: Online learning resources

D.1. Additional tutorials

D.2. Code libraries


About the book

This book helps readers build successful games with the Unity game development platform. You will use the powerful C# language, Unity's intuitive workflow tools, and a state-of-the-art rendering engine to build and deploy mobile, desktop, and console games. Unity's single codebase approach minimizes inefficient switching among development tools and concentrates your attention on making great interactive experiences.

Unity in Action teaches you how to write and deploy games. You'll master the Unity toolset from the ground up, adding the skills you need to go from application coder to game developer. Each sample project illuminates specifi c Unity features and game development strategies. As you read and practice, you’ll build up a well-rounded skill set for creating graphically driven 2D and 3D game applications.

What's inside

  • Program characters that run, jump, and bump into things
  • Build code architectures that manage the game's state
  • Connect your games to the Internet to download live data
  • Deploy games to platforms including web and mobile
  • Covers Unity 5

About the reader

You'll need to know how to program, in C# or a similar OO language. No previous Unity experience or game development knowledge is assumed.

About the author

Joe Hocking is a software engineer specializing in interactive media development. He works for Synapse Games and teaches classes in game development at Columbia College Chicago.

combo $44.99 pBook + eBook
eBook $35.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks

Gets you up and running in no time.

Sergio Arbeo, codecantor

The text is clear and concise, and the examples are outstanding.

Dan Kacenjar, Sr., Wolters Kluwer

All the roadblocks evaporated, and I took my game from concept to build in short order.

Philip Taffet, SOHOsoft LLC