In a game, there may be several different events that cause a particular sound effect to start playing. If the sound is already playing, then in almost all cases, we won't wish to restart the sound. This recipe includes a test, so that an Audio Source component is only sent a Play() message if it is currently not playing.
Preventing an Audio Clip from restarting if it is already playing
Getting ready
Try this with any audio clip that is one second or longer in duration. We have included the engineSound audio clip inside the 04_05 folder.
How to do it...
To prevent...