Appendix A. Initial State Machine files

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.

  • BeginState
  • SetupState
  • PlayStateScene1_1: (1 of 2 available States in Scene1)
  • PlayStateScene1_2: (2 of 2 available States in Scene1)
  • WonStateScene1
  • LostStateScene1
  • PlayStateScene2
  • WonStateScene2
  • LostStateScene2
  • StateManager
  • IStateBase

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.

BeginState

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");
    }
  }
}
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.118.138.195