In this recipe, you added two GameObjects to the scene that contain AudioSource components linked to music and dying sound clips. Additionally, you created a C# script class, called DelayedSoundManager, and added an instance to an empty GameObject. You associated the two AudioSource components in your GameObjects with the two public variables in your scripted component.
You created two buttons, as follows:
- Button-music, with a click action to invoke the DelayedSoundManager.ACTION_PlayMusicNow() method
- Button-dies, with a click action to invoke the DelayedSoundManager.PlayDiesSoundAfterDelay() method
The DelayedSoundManager.ACTION_PlayMusicNow() method immediately sends a Play() message to the audio source linked to the Pacman Opening Song AudioClip. However, the DelayedSoundManager.PlayDiesSoundAfterDelay() method sends a PlayDelayed(...) message to the audio source linked to the Pacman Dies AudioClip, passing a value of 1.0. This makes Unity wait one second...