Time for action – add sounds to FallingObject
Let's drop a couple of lines into the FallingObject script to fire off a few sounds:
Open the FallingObject script.
Declare a
clip1
variable at the top of the script:var prefab:GameObject; var speed:int; var clip1:AudioClip;
Just after we determine that the falling object has hit the ground, play the
clip1
sound:if(transform.position.y < 0) { audio.PlayOneShot(clip1);
By now, you've probably guessed that there's one more step involved. The script really has no idea what clip1
actually is—it's just a variable placeholder. Let's add some actual sound files to the Bomb and Stein Prefabs to get this party started:
In the Project panel, click to open the
SFX
folder. Yay—sounds!!Again in the Project panel, click to select the Bomb Prefab.
In the Inspector panel, locate the
clip1
variable in the FallingObject component.Click-and-drag the sound effect labeled explosion1 into the
clip1
variable slot.Repeat the previous steps for the Stein...