Game Development Reference
In-Depth Information
Dead Replacements
Now it would be nice if you could tell when you toasted a zombie bunny or when you missed. Let's
begin with a “dead replacement.” It will eventually need a healthy dose of black smoke to mark the
event. If you think back to Chapter 6, you may remember setting up the ToastedZombie with a nice
little animation.
The Toasted Zombie Parent will need to be instantiated from the ZombieBunny's ReceivedHit script.
1.
Open the ReceivedHit script.
2.
Add a variable for the dead replacement:
public GameObject deadReplacement; // this will be the ToastedZombie
At the top of the DestroyBun function, add the following:
3.
if (deadReplacement) {
// get the dead replacement object's parent
GameObject deadParent = deadReplacement.transform.parent.gameObject;
// instantiate the dead replacement's parent at this object's transform
GameObject dead = (GameObject) Instantiate(deadParent, transform.position, transform.
rotation);
// trigger its default animation
deadReplacement.GetComponent<Animator>().Play("Jump Shrink");
// destroy the dead replacement's parent after a second
Destroy(dead,1.4f);
}
Now that you have a replacement, change the Destroy(GameObject,0.2f) line to
4.
Destroy(gameObject, 0.001f); // destroy it after a brief pause
5.
Save the script.
6.
Assign the ToastedZombie part of the Toasted Zombie Parent prefabto the
ZombieBunny prefab's Dead Replacement parameter in the Received Hit
component in the Project view.
7.
Click Play, and test the new additions.
Now that the shoot/die sequence is together, you might want to shorten the pause before the
animation starts. To change the animation clip, you must temporarily drag a prefab into the scene.
1.
Drag the Toasted Zombie Parent into the Scene, and select the
ToastedZombie child.
2.
Open the Animation Window.
3.
Select all of the keys, and drag them to the left so that they start at about
0:15 , 15 frames (Figure 8-16 ).
 
Search WWH ::




Custom Search