Unity in Action, Second Edition
Multiplatform game development in C#
Joseph Hocking
  • MEAP began July 2017
  • Publication in March 2018 (estimated)
  • ISBN 9781617294969
  • 400 pages (estimated)
  • printed in black & white


An eBook copy of the previous edition, Unity in Action (First Edition), is included at no additional cost. It will be automatically added to your Manning Bookshelf within 24 hours of purchase.

Manning's bestselling and highly recommended Unity book has been fully revised! Unity in Action, Second Edition teaches you to write and deploy games with the Unity game development platform. You'll master the Unity toolset from the ground up, adding the skills you need to go from application coder to game developer. Inside, you'll 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. In each chapter, you'll discover new projects that introduce specific Unity features and game development strategies. As you read and practice, you'll learn everything from first-person control schemes to adding audio and interactive objects, as you build up a well-rounded skill set for creating and deploying amazing games. Fully updated to include the latest changes to Unity, new best practices, and an entire chapter on building 2D platformers with Unity's expanded 2D toolkit, this book is essential for any aspiring game developer.

"Reading the book is like having the author sitting next to me, teaching me in a 1-1 style on how to build games and force me to find the time to get building."

~ Robin Dewson

"A fantastic way to get up to speed quickly and effectively."

~ Dan Kacenjar

"I am new to the subject and was able to follow the content and understand it 100%."

~ Tanya Wilke

"Easily one of the best ways to learn Unity."

~ Shiloh Morris

Table of Contents detailed table of contents

Getting to know Unity

Why is Unity so great?

Unity's strengths and advantages

Downsides to be aware of

Example games built with Unity

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

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!


Building a demo that puts you in 3D space

Before you start…

Planning the project

Understanding 3D coordinate space

Begin the project: place objects in the scene

The scenery: floor, outer walls, inner walls

Lights and cameras

The player’s collider and viewpoint

Making things move: a script that applies transforms

Diagramming how movement is programmed

Writing code to implement the diagram

Local vs. global coordinate space

Script component for looking around: MouseLook

Horizontal rotation that tracks mouse movement

Vertical rotation with limits

Horizontal and vertical rotation at the same time

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


Adding enemies and projectiles to the 3D game

Shooting via raycasts

What is raycasting?

Using the command ScreenPointToRay for shooting

Adding visual indicators for aiming and hits

Scripting reactive targets

Determining what was hit

Alert the target that it was hit

Basic wandering AI

Diagramming how basic AI works

“Seeing” obstacles with a raycast

Tracking the character’s state

Spawning enemy prefabs

What is a prefab?

Creating the enemy prefab

Instantiating from an invisible SceneController

Shooting via instantiating objects

Creating the projectile prefab

Shooting the projectile and colliding with a target

Damaging the player


Developing graphics for your game

Understanding art assets

Building basic 3D scenery: whiteboxing

Whiteboxing explained

Drawing a floor plan for the level

Laying out primitives according to the plan

Texture the scene with 2D images

Choosing a file format

Importing an image file

Applying the image

Generating sky visuals using texture images

What is a skybox?

Creating a new skybox material

Working with custom 3D models

Which file format to choose?

Exporting and importing the model

Creating effects using particle systems

Adjusting parameters on the default effect

Applying a new texture for fire

Attaching particle effects to 3D objects


Part 2: Getting comfortable

Building a Memory game using Unity’s 2D functionality

Setting everything up for 2D graphics

Preparing the project

Displaying 2D images (aka sprites)

Switching the camera to 2D mode

Building a card object and making it react to clicks

Building the object out of sprites

Mouse input code

Revealing the card on click

Displaying the various card images

Loading images programmatically

Setting the image from an invisible SceneController

Instantiating a grid of cards

Shuffling the cards

Making and scoring matches

Storing and comparing revealed cards

Hiding mismatched cards

Text display for the score

Restart button

Programming a UIButton component using SendMessage

Calling LoadScene from SceneController


Creating a basic 2D Platformer

Setting Up the Graphics

Placing Walls and Floor

Importing Sprite Sheets

Moving the Player Left and Right

Writing Keyboard Controls

Colliding with the Walls

Playing the Sprite’s Animation

Explaining the Mecanim Animation System

Triggering Animations from Code

Adding the Ability to Jump

Falling from Gravity

Applying an Upward Impulse

Detecting the Ground

Additional Features for a Platform Game

Unusual Floors: Slopes and One-Way Platforms

Implementing Moving Platforms

Camera Control


Putting a GUI onto a game

Before you start writing code…

Immediate mode GUI or advanced 2D interface?

Planning the layout

Importing UI images

Setting up the GUI display

Creating a canvas for the interface

Buttons, images, and text labels

Controlling the position of UI elements

Programming interactivity in the UI

Programming an invisible UIController

Creating a pop-up window

Setting values using sliders and input fields

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


Creating a third-person 3D game: player movement and animation

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

Programming camera-relative movement controls

Rotating the character to face movement direction

Moving forward in that direction

Implementing the jump action

Applying vertical speed and acceleration

Modifying the ground detection to handle edges and slopes

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


Adding interactive devices and items within the game

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

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

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

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


Part 3: Strong finish

Connecting your game to the internet

Creating an outdoor scene

Generating sky visuals using a skybox

Setting up an atmosphere that’s controlled by code

Downloading weather data from an internet service

Requesting HTTP data using coroutines

Parsing XML

Parsing JSON

Affecting the scene based on weather data

Adding a networked billboard

Loading images from the internet

Displaying images on the billboard

Caching the downloaded image for reuse

Posting data to a web server

Tracking current weather: sending post requests

Server-side code in PHP


Playing audio: sound effects and music

Importing sound effects

Supported file formats

Importing audio files

Playing sound effects

Explaining what’s involved: Audio Clip vs. Source vs. Listener

Assigning a looping sound

Triggering sound effects from code

Audio control interface

Setting up the central AudioManager

Volume control UI

Playing UI sounds

Background music

Playing music loops

Controlling music volume separately

Fading between songs


Putting the parts together into a complete game

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

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

Handling the player’s progression through the game

Saving and loading the player’s progress

Beating the game by completing three levels


Deploying your game to players’ devices

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

Building for the web

Unity Player vs. HTML5/WebGL

Building the game embedded in a web page

Communicating with JavaScript in the browser

Building for mobile: iOS and Android

Setting up the build tools

Texture compression

Developing plug-ins



Appendix A: Scene navigation and keyboard shortcuts

Scene navigation using the mouse

Commonly used keyboard shortcuts

Appendix B: External tools used alongside Unity

Programming tools

Visual Studio


Android SDK

SVN, Git, or Mercurial

3D art applications


3ds Max



2D image editors




Aseprite, Pyxel Edit

Audio software

Pro Tools


Appendix C: Modeling a bench in Blender

Building the mesh geometry

Texture-mapping the model

Appendix D: Online learning resources

Additional tutorials

Code libraries

About the Technology

Great computer games combine sophisticated graphics, artful programming, specialized features, and even some advanced math and physics. Not for the faint of heart! Fortunately, the Unity game development platform handles a lot of the heavy lifting for you, so you can concentrate on delighting your users with entertaining gameplay. With its single codebase approach that minimizes inefficient switching among development tools and concentrates your attention on making great interactive experiences, Unity is perfect for game devs of all experience levels. You get an intuitive drag-and-drop GUI, along with support for deep scripting with C#. With a huge ecosystem of pre-built game assets, an enthusiastic community of fellow developers, and support for nearly every platform, Unity is a great choice to make your dream game a reality.

What's inside

  • Covers new best practices, Unity updates, and more
  • Work with 2D and 3D games
  • Characters that run, jump, and bump into things
  • Build code architectures that manage the game's state
  • Connect your games to the Internet
  • Deploy games to tons of platforms, such as web and mobile

About the reader

Written for those who 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 who specializes in interactive media development. He currently works for InContext Solutions and wrote the first edition while working for Synapse Games. He has also taught classes at the University of Illinois at Chicago, the School of the Art Institute of Chicago, and Columbia College Chicago.

Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
MEAP combo $44.99 pBook + eBook + liveBook
MEAP eBook $35.99 pdf + ePub + kindle + liveBook

FREE domestic shipping on three or more pBooks