Game Development Reference
In-Depth Information
4.
Open the ScoreKeeper script.
5.
Add the following variable:
public EndGameGUI endGameGUI; // the script that handles the GUI
You've already created a
GardenSecure
function in the event of the Player reaching a 0 zombie bunny
count. From that function, you will directly call the EndGameGUI script's
TriggerMessage
function,
passing in the appropriate text message.
In the
GardenSecure()
function, under
// if game over
, add the following:
6.
endGameGUI.TriggerMessage("Garden Secure");
7.
Save the script.
8.
Select the Game Manager object in the Hierarchy view, and drag it onto its In
Game GUI parameter in the Score Keeper component.
9.
Click Play, and test the “0 zombie bunnies left” ending.
The end GUI pops up on cue.
The other ending is triggered when the battery life runs out before the zombie bunny hordes have
been eradicated.
1.
Stop Play mode.
2.
In the Battery Life object, set the Battery Full to
10
for a quick battery drain.
Open the
BatteryHealth
script.
3.
4.
Add the following variable:
public EndGameGUI endGameGUI; // the script that handles the GUI
In the
GameOver
function, add
5.
// end of game options
endGameGUI.TriggerMessage("Garden Overrun");
6.
Save the script.
7.
Select the Battery Life object in the Hierarchy view, and drag the Game
Manager object onto its End Game GUI parameter in the Battery Health
component.
8.
Select the Game Manager, and set the Score Keeper's Stop Pop X parameter
to
10
to make sure the battery will drain.
9.
Click Play, and let the battery run out.
The “Garden Overrun” message appears when the battery life reaches 0.