Time for action – mix it up a bit
One of my personal beefs about sound design in games is when the sound effects are too samey. In our game, hearing the same two sound effects over and over again is wearying. One of the things I like to do is to create a bunch of slightly different sound effects for the same event, and when the time comes to play a sound, I just choose one of them at random. This can really vary the soundscape of the game and keep your player from overdosing on the same sound effects.
You probably noticed that the SFX
folder contained five versions of the smash and explosion sound effects. Let's learn how to set them up to play randomly:
Open the FallingObject script.
Delete the line where you define the
clip1
variable, and replace it with an array declaration:var prefab:GameObject; var speed:int; var audioClips : AudioClip[];
Modify the line where you play the sound:
audio.PlayOneShot(audioClips[Random.Range(0,audioClips.length)] );
Let's take a closer look at this new code...