Using AudioManager to Manage the Audio Effect- Game Dev Series 118

Objective: manage most of the sound effect by using AudioManager.

By using AudioManager singleton to manage the audio effects, would be easy and clear to separate the timing of calling these sound to play.
In this article, I would shortly demonstrate how to use AudioManager singleton in game.

Create AudioManager

As usual, create an empty object and a script called “AudioManager”.
And you will need an Audio Source component in this gameobject.

Create a singleton patten to AudioManager script. Then, we can make it works.

Import audio clips to script

Let’s create the sound effect of open the shop screen.
Create an AudioClip variable to store the sound clip.

Then also create an AudioSource variable, then get the reference in Start().

Now back to Editor to drag in the “Shop Open” sound clip.

Call and play

Next create a public method to play this clip.
Make sure locate the right audio clip before playing it.

And also you need to adjust the volume of this AudioSource and disable “Play On Awake”.
Once done, we can call this method from the script of shop.

With this, when Player enter the shop and open the shop menu, you should hear the sound clip that we imported.

Easy to replace the clip

If you need another sound effect, just create another variable and drag the file in.

And also create another public method to call and play it.

That would be really easy on playing the one-time-only audio clips by using singleton.



Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store