We'll add a single line of code in BeginState
and in LostState
to change Scenes.
BeginState
, add Application.LoadLevel("Scene1");
into the Switch()
method on line 42 as shown in the following screenshot:LostState
, add Application.LoadLevel("BeginningScene");
into the StateUpdate()
method on line 20 as shown in the following screenshot:If earlier in this chapter you changed WonState
to switch to PlayState
instead of starting over with BeginState
, we're ready to test our State Machine again. If you didn't, the following are the changes you need to make to WonState
:
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
.
Q1. The State classes implement the IStateBase
interface guaranteeing certain methods are included. What is the other very important feature that the interface provides for the State Machine?
Q2. Each State has to have the StateUpdate()
and ShowIt()
methods. What calls these methods?
Q3. What normally happens to GameObjects when changing to another Scene?
Q4. Is this sentence true or false? Once a State Machine is setup, it can't be changed.
Just in case you've had any difficulty because of constantly editing your class files, the following are the screenshots of StateManager
, BeginState
, PlayState
, WonState
, and LostState
as they currently stand.
The following is the screenshot of the StateManager
class:
The following is the screenshot of the BeginState
class:
The following is the screenshot of the PlayState
class:
18.117.74.231