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. Name this Text-state-messages, and set its Rect Transform height property to 300 and its Text (Script) Paragraph Vertical Overflow property to Overflow.
  3. Create a new C# script class, GameStates.cs:
    public class GameStates     {         public enum GameStateType         {             GamePlaying,             GameWon,             GameLost,         }     } 
  1. Create the MyGameManager.cs C# script class, and add an instance object as a component to the Main Camera:
    using UnityEngine; using ...

Get Unity 2018 Cookbook - Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.