Unity Game Development Cookbook

Book Description

Discover how to use the Unity game engine to its full potential for both 3D and 2D game development—from the basics of scripting to useful tricks in gameplay, behavior, and animation. With this problem-solving cookbook, you’ll get started in two ways:

First, you’ll learn about the Unity game engine through brief recipes that teach specific features of the software and scripting systems.

Second, you’ll apply a collection of snippets to address common gameplay scenarios, such as properly keeping score.

Using our cookbook format, we pinpoint the problem, set out the solution, and discuss how to solve your problem in the best and most straightforward way possible. This book is ideal for beginning to intermediate Unity developers.

You’ll find solutions for:

  • 2D and 3D graphics
  • Math, physics, and character control
  • Animation and movement
  • Behavior and AI
  • Sound and music
  • Input and gameplay
  • Scripting and user interface

Publisher Resources

View/Submit Errata

Table of Contents

  1. Preface
    1. Resources Used in This Book
    2. Audience and Approach
    3. Organization of This Book
    4. Conventions Used in This Book
    5. Using Code Examples
    6. O’Reilly Online Learning Platform
    7. How to Contact Us
    8. Acknowledgments
  2. 1. Working with Unity
    1. 1.1. Getting Around in Unity
    2. 1.2. Working with Game Objects
    3. 1.3. Working with Components
    4. 1.4. Working with Prefabs
    5. 1.5. Working with Scenes
    6. 1.6. Managing Assets
    7. 1.7. Building Unity Projects
    8. 1.8. Accessing Preferences
  3. 2. Scripting
    1. 2.1. Working with MonoBehaviours
    2. 2.2. Using Callbacks
    3. 2.3. Creating Frame Rate–Independent Behavior
    4. 2.4. Accessing Components
    5. 2.5. Finding Objects
    6. 2.6. Using Coroutines
    7. 2.7. Singletons
    8. 2.8. Loading a Level (Scene)
    9. 2.9. Storing Data on Disk
    10. 2.10. Saving and Loading the Game State
    11. 2.11. Managing Objects Using an Object Pool
    12. 2.12. Storing Data in Assets Using ScriptableObject
  4. 3. Input
    1. 3.1. Working with Keyboard Input
    2. 3.2. Working with Mouse Input
    3. 3.3. Locking and Hiding the Mouse Cursor
    4. 3.4. Working with Gamepads
    5. 3.5. Customizing Unity’s Input System
    6. 3.6. Responding to Pointer Events from the Event System
  5. 4. Math
    1. 4.1. Storing Coordinates of Varying Dimensions Using Vectors
    2. 4.2. Rotating in 3D Space
    3. 4.3. Performing Transformations in 3D Space with Matrices
    4. 4.4. Working with Angles
    5. 4.5. Finding the Distance to a Target
    6. 4.6. Finding the Angle to a Target
  6. 5. 2D Graphics
    1. 5.1. Importing Sprites
    2. 5.2. Adding a Sprite to the Scene
    3. 5.3. Creating a Sprite Animation
    4. 5.4. Creating a Sprite with 2D Physics
    5. 5.5. Customizing Sprite Collision Shapes
    6. 5.6. Using a Composite Collider
    7. 5.7. Using the Sprite Packer
    8. 5.8. Applying Forces to 2D Objects
    9. 5.9. Creating a Conveyor Belt
    10. 5.10. Using a Custom Material for Sprites
    11. 5.11. Managing Sprite Sorting
    12. 5.12. Using Sorting Groups
    13. 5.13. Creating a 2.5D Scene
  7. 6. 3D Graphics
    1. 6.1. Creating a Simple Material
    2. 6.2. Controlling a Material’s Property Through a Script
    3. 6.3. Creating an Unlit Material
    4. 6.4. Setting Up a Material Using Textures
    5. 6.5. Making a Material Use a Shader
    6. 6.6. Setting Up a Bloom Effect Using Post-Processing
    7. 6.7. Using High-Dynamic-Range Colors
    8. 6.8. Setting Up a Project to Use a Scriptable Render Pipeline
    9. 6.9. Creating a Shader Using the Shader Graph
    10. 6.10. Creating a Glowing Effect Using the Shader Graph
    11. 6.11. Exposing Properties from a Shader Graph
    12. 6.12. Animating a Shader over Time
    13. 6.13. Controlling the Speed of an Animated Shader
    14. 6.14. Using a Subgraph to Reuse Graph Components
    15. 6.15. Implementing a Dissolve Effect Using a Shader Graph
    16. 6.16. Using Baked Lighting and Real-Time Lighting
    17. 6.17. Using Baked Emission Sources
    18. 6.18. Making Static Objects Cast Shadows on Dynamic Objects
    19. 6.19. Using Light Probes to Influence Lighting
    20. 6.20. Using Reflection Probes
    21. 6.21. Faking a Dynamic Emissive Object
    22. 6.22. Loading Textures from Disk
    23. 6.23. Rendering to a Texture
    24. 6.24. Saving Screenshots
  8. 7. Physics and Character Control
    1. 7.1. Understanding FixedUpdate
    2. 7.2. Implementing Mouselook
    3. 7.3. Controlling a 3D Character
    4. 7.4. Interacting with Switches and Objects
    5. 7.5. Picking Up and Putting Down Objects
    6. 7.6. Detecting When an Object Is Touching Another Object
    7. 7.7. Detecting When an Object Is in a Trigger Area
    8. 7.8. Implementing Moving Platforms
    9. 7.9. Implementing Platform Riding
    10. 7.10. Responding to Being Pushed by Objects
  9. 8. Animation and Movement
    1. 8.1. Animating an Object
    2. 8.2. Basic Character Movement
    3. 8.3. Inverse Kinematics
    4. 8.4. Masked Movement
    5. 8.5. Blended Movement
    6. 8.6. Navigation and Animating in Sync
    7. 8.7. Cinematic Camera Tracking
    8. 8.8. Automatically Switching Cameras
    9. 8.9. Keeping Multiple Objects in View
    10. 8.10. Dollying a Camera
  10. 9. Gameplay
    1. 9.1. Managing Quests
    2. 9.2. Managing Hitpoints
    3. 9.3. Creating a Top-Down Camera
    4. 9.4. Dragging a Box to Select Objects
    5. 9.5. Creating a Menu Structure
    6. 9.6. Creating a Wheeled Vehicle
    7. 9.7. Keeping a Car from Tipping Over
    8. 9.8. Creating Speed Boosts
    9. 9.9. Creating a Camera That Orbits Around Its Target
    10. 9.10. Creating Orbiting Cameras That Won’t Clip Through Walls
    11. 9.11. Detecting When the Player Has Completed a Lap
  11. 10. Behavior and AI
    1. 10.1. Defining a Path That AI Entities and the Player Can Follow
    2. 10.2. Letting Entities in Your Game Follow a Path
    3. 10.3. Enemies Detecting When They Can See the Player
    4. 10.4. Finding a Good Distribution of Random Points (Poisson Disc)
    5. 10.5. Enemies Detecting Where They Can Take Cover
    6. 10.6. Building and Using a State Machine
  12. 11. Sound and Music
    1. 11.1. Playing Sounds
    2. 11.2. Setting Up a Mixer
    3. 11.3. Using Audio Effects
    4. 11.4. Using Send and Receive Effects
    5. 11.5. Ducking
    6. 11.6. Using Multiple Audio Zones
    7. 11.7. Playing Audio Through Code
    8. 11.8. Using a Sound Manager
  13. 12. User Interface
    1. 12.1. Working with UI Controls
    2. 12.2. Theming Controls
    3. 12.3. Animating the UI
    4. 12.4. Creating a List of Items
    5. 12.5. Fading Out List Items
    6. 12.6. Creating Onscreen Position Indicators
    7. 12.7. Custom Editors
    8. 12.8. Property Drawers
    9. 12.9. Attribute Drawers
    10. 12.10. Asset Processing
    11. 12.11. Scripted Importers
    12. 12.12. Wizards
  14. Index

Product Information

  • Title: Unity Game Development Cookbook
  • Author(s): Paris Buttfield-Addison, Jon Manning, Tim Nugent
  • Release date: March 2019
  • Publisher(s): O'Reilly Media, Inc.
  • ISBN: 9781491999158