Time for action – modify StateManager

Edit the StateManager class to use the IStateBase interface. This allows the activeState variable to store all of the State class objects. Also add the code that does the switching to the next State:

  1. Modify StateManager as shown in the next screenshot.
  2. Remove the Debug.Log statement.
  3. Save all files.
  4. In Unity click on Play.
  5. Now press the Space bar key to cycle through the States.
    Time for action – modify StateManager

What just happened?

The following is the output to the Console as you repeatedly press the Space bar key:

What just happened?

The State Machine starts with BeginState ...

Get Learning C# by Developing Games with Unity 3D Beginner's Guide 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.