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

GET MORE WITH MANNING

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

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 coordinate 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. Instantiating 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

Getting comfortable

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

5.6. Summary

6. Creating a basic 2D Platformer

6.1. Setting Up the Graphics

6.1.1. Placing Walls and Floor

6.1.2. Importing Sprite Sheets

6.2. Moving the Player Left and Right

6.2.1. Writing Keyboard Controls

6.2.2. Colliding with the Walls

6.3. Playing the Sprite’s Animation

6.3.1. Explaining the Mecanim Animation System

6.3.2. Triggering Animations from Code

6.4. Adding the Ability to Jump

6.4.1. Falling from Gravity

6.4.2. Applying an Upward Impulse

6.4.3. Detecting the Ground

6.5. Additional Features for a Platform Game

6.5.1. Unusual Floors: Slopes and One-Way Platforms

6.5.2. Implementing Moving Platforms

6.5.3. Camera Control

6.6. Summary

7. Putting a GUI onto a game

7.1. Before you start writing code…

7.1.1. Immediate mode GUI or advanced 2D interface?

7.1.2. Planning the layout

7.1.3. Importing UI images

7.2. Setting up the GUI display

7.2.1. Creating a canvas for the interface

7.2.2. Buttons, images, and text labels

7.2.3. Controlling the position of UI elements

7.3. Programming interactivity in the UI

7.3.1. Programming an invisible UIController

7.3.2. Creating a pop-up window

7.3.3. Setting values using sliders and input fields

7.4. Updating the game by responding to events

7.4.1. Integrating an event system

7.4.2. Broadcasting and listening for events from the scene

7.4.3. Broadcasting and listening for events from the HUD

7.5. Summary

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

8.1. Adjusting the camera view for third-person

8.1.1. Importing a character to look at

8.1.2. Adding shadows to the scene

8.1.3. Orbiting the camera around the player character

8.2. Programming camera-relative movement controls

8.2.1. Rotating the character to face movement direction

8.2.2. Moving forward in that direction

8.3. Implementing the jump action

8.3.1. Applying vertical speed and acceleration

8.3.2. Modifying the ground detection to handle edges and slopes

8.4. Setting up animations on the player character

8.4.1. Defining animation clips in the imported model

8.4.2. Creating the animator controller for these animations

8.4.3. Writing code that operates the animator

8.5. Summary

9. Adding interactive devices and items within the game

9.1. Creating doors and other devices

9.1.1. Doors that open and close on a keypress

9.1.2. Checking distance and facing before opening the door

9.1.3. Operating a color-changing monitor

9.2. Interacting with objects by bumping into them

9.2.1. Colliding with physics-enabled obstacles

9.2.2. Triggering the door with a pressure plate

9.2.3. Collecting items scattered around the level

9.3. Managing inventory data and game state

9.3.1. Setting up player and inventory managers

9.3.2. Programming the game managers

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

9.4. Inventory UI for using and equipping items

9.4.1. Displaying inventory items in the UI

9.4.2. Equipping a key to use on locked doors

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

9.5. Summary

Strong finish

10. Connecting your game to the internet

10.1. Creating an outdoor scene

10.1.1. Generating sky visuals using a skybox

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

10.2. Downloading weather data from an internet service

10.2.1. Requesting HTTP data using coroutines

10.2.2. Parsing XML

10.2.3. Parsing JSON

10.2.4. Affecting the scene based on Weather Data

10.3. Adding a networked billboard

10.3.1. Loading images from the internet

10.3.2. Displaying images on the billboard

10.3.3. Caching the downloaded image for reuse

10.4. Posting data to a web server

10.4.1. Tracking current weather: sending post requests

10.4.2. Server-side code in PHP

10.5. Summary

11. Playing audio: sound effects and music

11.1. Importing sound effects

11.1.1. Supported file formats

11.1.2. Importing audio files

11.2. Playing sound effects

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

11.2.2. Assigning a looping sound

11.2.3. Triggering sound effects from code

11.3. Audio control interface

11.3.1. Setting up the central AudioManager

11.3.2. Volume control UI

11.3.3. Playing UI sounds

11.4. Background music

11.4.1. Playing music loops

11.4.2. Controlling music volume separately

11.4.3. Fading between songs

11.5. Summary

12. Putting the parts together into a complete game

12.1. Building an action RPG by repurposing projects

12.1.1. Assembling assets and code from multiple projects

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

12.1.3. Replacing the old GUI with a new interface

12.2. Developing the overarching game structure

12.2.1. Controlling mission flow and multiple levels

12.2.2. Completing a level by reaching the exit

12.2.3. Losing the level when caught by enemies

12.3. Handling the player’s progression through the game

12.3.1. Saving and loading the player’s progress

12.3.2. Beating the game by completing three levels

12.4. Summary

13. Deploying your game to players’ devices

13.1. Start by building for the desktop: Windows, Mac, and Linux

13.1.1. Building the application

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

13.1.3. Platform-dependent compilation

13.2. Building for the web

13.2.1. Unity Player vs.

13.2.2. Building the game embedded in a web page

13.2.3. Communicating with JavaScript in the browser

13.3. Building for mobile apps: iOS and Android

13.3.1. Setting up the build tools

13.3.2. Texture compression

13.3.3. Developing plug-ins

13.4. Summary

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 JavaScript and 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.
Buy
MEAP combo $44.99 pBook + eBook + liveBook
MEAP eBook $35.99 pdf + ePub + kindle + liveBook

FREE domestic shipping on three or more pBooks