Game Development Reference
In-Depth Information
11.
Save the script.
12.
Activate the Gnome Arrow again.
13.
Click Play, and test.
The laser is much more efficient than the potato gun. In fact, it's hardly sporting, not to mention it
makes the game too easy to win. It might be fun to automatically activate it around the same time
the slug is sent zipping through the garden, a sort of “Hail Mary,” or last-ditch attempt, to help the
player get control of the situation. The aim is quite a bit off from the potato gun, so the player will
have to make a quick choice on how best to deal with the remaining zombie bunnies.
Before adding that last refinement, you will want to make sure the laser is turned off when the battery
runs out. Also, in keeping with the concept of the battery powering the Gnomatic Garden Defender,
you should change the state of the GardenGnome so that it no longer plays the idle animation when
the battery is dead. You can take care of all three tasks in the BatteryHealth script.
1.
Select the GardenGnome, and open its Gnome Controller.
2.
In the Animator view, right-click somewhere and select Create State, Empty.
3.
Name it Dead Battery .
4.
Open the BatteryHealth script.
At the bottom of the GameOver function, add
5.
// turn off gnome animations
Animator gnome = GameObject.Find("GardenGnome").GetComponent<Animator>();
gnome.Play("Dead Battery"); // turn off the gnome animation
gnome.SetBool("Armed", false); // close the hat
gnome.SendMessage("BeamOff", SendMessageOptions.DontRequireReceiver);
// deactivate the laser stuff
6.
Save the script.
7.
Click Play, and test by losing the game.
Now when the game is lost, the Gnomatic Garden Defender and its related functionality is turned off.
The final task is to decide when the player will have access to the laser weapon. An easy solution
is to piggy-back onto the slug activation in the BatteryHealth script. By activating the laser shortly
before the slug, the player can be tricked into missing the slug power-up.
At the top of the BatteryHealth script's ManageSlug function, add the following:
8.
if (percentRemaining == slugTime + 10) {
GameObject.Find("GardenGnome").SendMessage("OpenHat",SendMessageOptions
.DontRequireReceiver);
}
9.
Save the script.
 
Search WWH ::




Custom Search