State-driven behavior Do-It-Yourself states

Games as a whole, and individual objects or characters, can often be thought of (or modeled as) passing through different states or modes. Modeling states and changes of state (due to events or game conditions) is a very common way to manage the complexity of games and game components. In this recipe, we create a simple three-state game (game playing/game won/game lost) using a single GameManager class.

How to do it...

To use states to manage object behavior, follow these steps:

  1. Create two UI buttons at the top middle of the screen. Name one Button-win and edit its text to read Win Game. Name the second Button-lose and edit its text to read Lose Game.
  2. Create a UI text object at the top left of the screen. ...

Get Unity 5.x Cookbook now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.