Unity Game Development Cookbook
by Paris Buttfield-Addison , Jon Manning , and Tim Nugent
Copyright 2019 Secret Lab. All rights reserved.
Printed in the United States of America.
Published by OReilly Media, Inc. , 1005 Gravenstein Highway North, Sebastopol, CA 95472.
OReilly books may be purchased for educational, business, or sales promotional use. Online editions are also available for most titles (http://oreilly.com). For more information, contact our corporate/institutional sales department: 800-998-9938 or corporate@oreilly.com .
- Acquisition Editor: Rachel Roumeliotis
- Editor: Jeff Bleiel
- Production Editor: Deborah Baker
- Copyeditor: Rachel Monaghan
- Proofreader: Kim Cofer
- Indexer: Judy McConville
- Interior Designer: David Futato
- Cover Designer: Karen Montgomery
- Illustrator: Rebecca Demarest
- April 2019: First Edition
Revision History for the First Edition
- 2019-03-12: First Release
See http://oreilly.com/catalog/errata.csp?isbn=9781491999158 for release details.
The OReilly logo is a registered trademark of OReilly Media, Inc. Unity Game Development Cookbook, the cover image, and related trade dress are trademarks of OReilly Media, Inc.
While the publisher and the authors have used good faith efforts to ensure that the information and instructions contained in this work are accurate, the publisher and the authors disclaim all responsibility for errors or omissions, including without limitation responsibility for damages resulting from the use of or reliance on this work. Use of the information and instructions contained in this work is at your own risk. If any code samples or other technology this work contains or describes is subject to open source licenses or the intellectual property rights of others, it is your responsibility to ensure that your use thereof complies with such licenses and/or rights.
978-1-491-99915-8
[GP]
Preface
Welcome to the Unity Game Development Cookbook! Were incredibly excited about this book, and really proud of our work on it. We hope you find it a useful companion to your game development using the Unity engine.
Unity is an amazing platform, and the more you use it the more youll come up with new ideas on how you can use it, why you could use it, and so on! Its all very exciting. Trust us, weve been there.
As Secret Lab, we use Unity to build most of our video games. Were best known for building childrens games in Australia, as well as our contributions to the BAFTA- and IGF-winning Night in the Woods. We discovered Unity more than a decade ago, and we havent stopped using it since.
In this book, weve assembled a selection of recipes to solve common problems that we found ourselves solving over and over as we build video games using Unity. This book wont cover every single tiny thing you want to know about Unity, but it hopefully covers the majority of things youd be doing day-to-day in video game development.
These recipes are about things we wish we had someone to ask about back when we were first building our own games. We really hope they help you!
Its a really exciting time to be using Unity. The game development world is getting bigger and more interesting every day, and the tools and technologies we use are better than ever.
Go out and build great games!
Tip
If you want to get more resources for this book, and our other books, check out our website.
Resources Used in This Book
If you want to download all our code from the recipes throughout this book, head to https://github.com/thesecretlab/unity-game-development-cookbook-1e. We also have a dedicated page for this book, where we keep both the source code as well as other downloads and resources.
Audience and Approach
This book assumes that you know a little of the C# programming language, or a similar language like C++, Java, Go, Swift, Python, or other common languages, but dont know anything about Unity. This book is intended to be a companion to get your games up and running faster.
Tip
If you like our style, and want to read more Unity material from us, you can learn Unity from scratch in Mobile Game Development with Unity, also available from the fine folks at OReilly.
Our screenshots are taken with macOS, but everything we talk about is generally applicable to Unity on Windows, macOS, or Linux.
Organization of This Book
This book is arranged into 12 chapters:
introduces the fundamental concepts you need to know in order to use Unity: game objects, components, scenes, and how to work with the Unity editor itself.
covers the scripting interface of Unity, which is the way you write the actual code that defines the way your game works. After we establish the basics, well dive into some practical examples, including how to write a save and load system, how to efficiently work with objects, and how to store your data in a way that both your code and Unity can work with easily.
In , youll learn how to get input from your user, in the form of keyboard input, the mouse, and from game pads. Well also discuss how to set up game objects that react to input events, like the user clicking on them.
covers the fundamentals of some of the mathematical concepts that are useful to know about when development games, such as vectors, matrices and quaternions. Well also look at some practical uses of these concepts, like detecting if an object is in front of the player or not.
discusses the 2D graphics and physics systems that are built in to Unity. Youll learn how to display sprites, sort them, and make them bounce off each other.
covers the material and shading system of Unity: how materials and shaders work, how to build a shader in Unity, and how to get the best results in your scenes.
In , youll learn how to make the 3D physics system of Unity do what you need it to in order to support common gameplay tasks, like picking up and throwing objects, and creating a moving platform that the player can ride on.
introduces the animation system used in Unity, and covers topics like how to set up a character to blend between different animation states, and how to integrate player movement with character animation. Well also introduce the camera system in Unity, and discuss how to set up cameras that move to follow targets.
is all about creating the gameplay that players interact with. Theres a wide range of common gameplay tasks in here, like managing the state of a quest that youve given the player, tracking if a racing car is taking too much of a shortcut, and managing how damage gets dealt between objects in your game.
In , youll learn how to add brains to your characters, including the ability to detect when the player can be seen, the ability to navigate a space and avoid obstacles, and the ability to figure out a place where they cant be seen.
introduces the audio systems in Unity. Well cover the basics of playing sounds, and then move on to more advanced features, like routing audio to multiple groups, and automatically ducking the music when a character is speaking.
, our final chapter, covers the tools for building an interface for your players to look at and interact with. Well cap the whole book off with a section on how to build your own tools in Unity, by extending the editor.
Conventions Used in This Book
The following typographical conventions are used in this book: