Game Development Reference
In-Depth Information
Figure 8-16. The ToastedZombie's animation keys shifted left to shorten the pause
4.
Drag the time indicator, and watch the object in the scene.
5.
Close the Animation view, and delete the ToastedZombie from the Scene.
Back in the ReceivedHit script, change the Destroy(dead,1.4f) line to:
6.
Destroy(dead,1.0f);
7.
Save the script.
You've probably noticed the BunnyScream audio clip in the Sound FX folder and are wondering
when you will be using it. Until now, you've had nowhere to put it. If it was put on the zombie bunny
or the potato, the object would be destroyed about the time you wanted the sound effect to play,
so it would never be heard. With the dead replacement being instantiated about the same time, you
now have a perfect container for the audio clip.
8.
Add an Audio Source component to the Toasted Zombie Parent prefab.
9.
Load the BunnyScream as its Audio Clip.
10.
Do not turn off “Play on Awake.”
11.
Click Play and test.
The same sound effect played on every hit gets old fast. A little script to load a random sound from
an array will improve things greatly. Audio.PlayOneShot is perfect for playing audio clips without the
need to replace existing clips.
1.
Create a new C# Script, and name it RandomSound .
2.
Create a variable to hold the possible audio clips:
AudioClip SoundFX[]; // audio clips
Search WWH ::




Custom Search