O'Reilly logo

Learning C# by Developing Games with Unity 3D Beginner's Guide by Terry Norton

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required