
上QQ阅读APP看书,第一时间看更新
How it works...
You add two GameObjects to the scene, containing AudioSources linked to music and dying sound clips. You created a C# script class, DelayedSoundManager, and added an instance to an empty GameObject. You associated the two AudioSources in your GameObjects with the two public variables in your scripted component.
You created two buttons:
- 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, making Unity wait 1 second before playing the sound clip.