These are the State Machine files mentioned at the beginning of Chapter 9, Start Building a Game and Get the Basic Structure Running, necessary for our Unity project.
This is how the files should be coded to begin Chapter 9, Start Building a Game and Get the Basic Structure Running. These make the State Machine functional for switching States and Scenes.
Each one will be modified as we progress through Chapters 9, Start Building a Game and Get the Basic Structure Running and Chapter 10, Moving Around, Collisions, and Keeping Score.
using UnityEngine; using Assets.Code.Interfaces; namespace Assets.Code.States { public class BeginState : IStateBase { private StateManager manager; public BeginState (StateManager managerRef) { manager = managerRef; if(Application.loadedLevelName != "Scene0") Application.LoadLevel("Scene0"); } public void StateUpdate () { if (Input.GetKeyUp (KeyCode.Space)) { manager.SwitchState (new SetupState (manager)); } } public void ShowIt () { Debug.Log ("In BeginState"); } } }
18.220.111.87