Game Development Reference
In-Depth Information
At this point, currentBunCount = 0 , the garden is secure, so the game should either end or open up
a new level. You won't deal with levels until Chapter 10, but you can block in the code for whatever
eventuality you will end up providing for.
13.
In the ScoreKeeper script, add the following above the
if (currentBunCount == 1) section:
if (currentBunCount == 0) { // garden secure
GardenSecure();
return;
}
And then add the GardenSecure() function:
14.
void GardenSecure(){
// if game over
// if more gardens
// if more levels
}
There are obviously lots of things you can do here, so at this point, it makes sense to block in the
options with no code.
There's one last detail of game play that you will add before getting into the 2D section of this
chapter. Now that the zombie bunnies can be fully eradicated, some of the pressure has been taken
off of the player. To make the player work a little harder, you will introduce the concept of battery life
for the Gnomatic Garden Defender's power source.
In effect, this is just another sort of timer. The battery life will drop throughout the game. If the player
gets rid of all of the zombie bunnies before the battery runs out, the game is won. If the battery runs
out first, the player has lost. Let's start the countdown once the Gnomatic Garden Defender has
entered the garden. You will create a GUI Texture to hold the countdown.
1.
Duplicate the Bunny Count GUI Texture object, and name it Battery Life .
2.
Set its X Position value to 0.05 .
3.
Create a new C# Script in the Game Scripts folder, and name it
BatteryHealth .
4.
Add the following variables just beneath the class declaration:
public float batteryFull = 70.0f; // battery life in seconds
float batteryRemaining; // remaining battery life in seconds
int percentRemaining; // converted to percent
bool trackingBattery = true; // timer not started
GUIText guiTxt; // the GUI Text component
 
Search WWH ::




Custom Search