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:
- Modify
StateManager
as shown in the next screenshot. - Remove the
Debug.Log
statement. - Save all files.
- In Unity click on Play.
- Now press the Space bar key to cycle through the States.
What just happened?
The following is the output to the Console as you repeatedly press the Space bar key:
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.