Game Development Reference
In-Depth Information
If you check the PotatoAmmo prefab, you will see that it is tagged as Ammo.
2.
Add the coroutine:
IEnumerator HitDestroy () {
GetComponent<Animator>().Play("Slug Hit");
audio.Play(); // play death fx
yield return new WaitForSeconds(1);
// reset battery
DestroySlug();
}
3.
Save the script.
4.
Add an Audio Source component to the Slug prefab in the Project view, and
assign the SlugZap audio clip to it.
5.
Uncheck Play On Awake.
6.
Click Play, drive the Gnomatic Garden Defender into the garden, and try to
shoot the slug as it goes through.
The slug jumps into the air when hit, accompanied by a nice high-voltage crackle.
Once the slug is hit, you will want to refresh the charge on the battery.
In the SlugManager, under the //reset battery line, add the following:
7.
batteryHealth.batteryRemaining = batteryHealth.batteryFull;
8.
Save the script.
9.
Click Play, and test.
The battery is recharged.
To set it to full each time is probably too easy, especially as you will be setting the slug to run
through when the charge is a lot lower.
1.
Change the line to
batteryHealth.batteryRemaining = batteryHealth.batteryFull / 2; // half charge
2.
Save the script.
3.
In the BatteryHealth script, add a new variable:
int slugTime; // battery % to cue the slug
In the Start function, add
4.
slugTime = Random.Range(30,10);
 
Search WWH ::




Custom Search