Time for action – adding the code to change the Scenes
We'll add a single line of code in BeginState
and in LostState
to change Scenes.
In
BeginState
, addApplication.LoadLevel("Scene1");
into theSwitch()
method on line 42 as shown in the following screenshot:In
LostState
, addApplication.LoadLevel("BeginningScene");
into theStateUpdate()
method on line 20 as shown in the following screenshot:If earlier in this chapter you changed
WonState
to switch toPlayState
instead of starting over withBeginState
, we're ready to test our State Machine again. If you didn't, the following are the changes you need to make toWonState
:Save all your changes.
Have BeginningScene loaded and showing in Unity.
Click on Play.
What just happened?
You should now be changing Scenes as you go from BeginState
to PlayState
. To get back to BeginState
, you have to first switch to LostState
.
Pop quiz – understanding State Machine operation
Q1. The State classes implement the IStateBase
interface guaranteeing certain methods...