AudioManager - Sound effects, music & voiceovers in Unity

What do you actually do when someone clicks a button in the game menu to play a sound? Let me guess: You add an AudioSource to the button. Then you add an AudioClip to the AudioSource. And when someone clicks on the button, you start the AudioSource. Isn't that complicated as heck? Do you really need a separate AudioSource for each button? Probably not. And that's also true for music or voice-overs in cutscenes. That's why I developed an AudioManager.

How to use the AudioManager

The AudioManager provides three different AudioSources for music, sound effects and voice-over. It also manages the volume for all these AudioSources as well as the master volume. This makes it easy to play sound effects without having to configure a separate AudioSource each time. The AudioManager provides some helpful methods and public variables for this purpose.

Find out if music, sounds or voiceovers are playing:

if (AudioManager.service?.isMusicPlaying) {
  // Do stuff...
}
if (AudioManager.service?.isAudioPlaying) {
  // Do stuff...
}
if (AudioManager.service?.isVoicePlaying) {
  // Do stuff...
}

Adjust the volume of the master, music, sound or voice player:

AudioManager.service?.masterVolume = 1f;
AudioManager.service?.musicVolume = 0.5f;
AudioManager.service?.soundVolume = 0.8f;
AudioManager.service?.voiceVolume = 0.2f;

Use the set volume to update the volume of AudioSources:

myAudioSource.volume = AudioManager.service?.musicVolume * AudioManager.service?.masterVolume;
myAudioSource.volume = AudioManager.service?.soundVolume * AudioManager.service?.masterVolume;
myAudioSource.volume = AudioManager.service?.voiceVolume * AudioManager.service?.masterVolume;

Play or pause sound effects, music, and voice-overs:

AudioManager.service?.PlayMusic(myMusicClip);
AudioManager.service?.StopMusic();

AudioManager.service?.PlaySound(mySoundClip);
AudioManager.service?.StopSound();

AudioManager.service?.PlayVoice(myVoiceClip);
AudioManager.service?.StopVoice();

Your Feedback is important!

What do you think of the services presented here? Is there anything missing or does something not work as expected? As always, I'm happy to listen to your feedback. Let me know what you think about this module. You can use the comment section below the article for this. You can also find other ways to contact me here. If you found a bug or want an enhancement, please create an issue in the GitHub repository. Further documentation can be found in the README of the corresponding module.

There are no comments yet.