Game Development Reference
In-Depth Information
In the BatteryHealth script, change the bool running line to
10.
internal bool running; // flag for active slug
11.
Save the script.
12.
Drag the SlugManager script onto the Slug prefab in the Project view.
13.
Click Play, and watch the Scene view to make sure the slug is destroyed after
it has left the garden (Figure 11-10 ).
Figure 11-10. The slug clear of the garden, just before it is destroyed
14.
Select the Slug in the Hierarchy view, and in the Inspector, click Apply to
update the Slug prefab. Then delete it from the Hierarchy view.
15.
Click Play, and drive the Gnomatic Garden Defender into the garden.
The slug zips through the scene when the battery has reached 90%.
Before refining the slug triggering mechanism, you will want to set it up for a hit by the potato gun.
When hit, it will go into its Slug Hit clip/state before it is deleted, so you will use another coroutine.
1.
Add the following to the SlugManager script:
void OnCollisionEnter (Collision collision) {
if (collision.transform.tag == "Ammo") {
StartCoroutine (HitDestroy()); // if it was tagged as Ammo,
process its destruction
}
}
 
Search WWH ::




Custom Search