Creating an Audio Manager

Centralizing the voice over clips

As we have mentioned in the previous article about Singleton patterns being used by higher tier management scripts, we are going to assign the Audio Manager to an singleton pattern as well.

Creating the Audio Manager Singleton:

Just like how we set up the Game Manager, we need a “private static (static variables means that this class is now saved within memory and can be referenced anywhere at anytime) handle” for the instance. It is set to private because we don’t want to have anything or anyone to tamper with the settings of this manager class.

Setting Up an Singleton Pattern for the Audio Manager

Then we need a public property which gives access to the singleton pattern. This should house the “get” setting which allows access to the singleton data or function.

Finally we finish off the singleton pattern with an Awake method to call this class before anything else has been activated. We make sure that the instance shall only be this class, and this class only.

Adding the Audio Clips:

Now that the singleton pattern is completed, it is time to add functionality to this class. Back in Unity, we first need to create an empty child object within the Audio Manager. This child object will house an modular Audio Source component which we can feed in different audio clip through different triggers.

With this setting, we can adjust one audio source component once, and it will affect every voice over clip.

In the script, we need to create a public handle for the new audio source component. Then we need to have a public method which can be access by the the voice over trigger script, to play the audio clip.

The property “AudioClip clipToPlay” at the method is added to reference the audio clip data that belongs to trigger we have collided with. Then we assign the empty audio source component to the collided audio clip so we can play it.

In the Voice Over Trigger script, instead of playing audio on point, we are now going to access our Audio Manager to pass in the audio clip data. The trigger script is not going to play the audio anymore since the Audio Manager is now responsible for that.

Voice Over Trigger Script passing the audio clip data to the Audio Manager to Play sound.

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Lining up Audio & Visual to Build Cutscenes in Unity

What Is Taxonomy in Digital Asset Management?

These 10 Flutter Widgets Every Developer Should Know

TWiGCP “Eventarc, Cloud SQL Insights, BeyondCorp Enterprise, Dialogflow CX, Cloud DNS policies…

[Tech Blog] Migration from REST API to Google PubSub in AnyTag

A Framework for Flutter Part 2

Product Owner Checklist for the Sprint Planning

Learning more about Ruby on Rails ActiveRecord

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
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.

More from Medium

Unity Features 101: Assembly Definitions

Creating a Loot system (part 1)

Moving onto 3D: Environments and Lighting (Game Dev Day 46)

Did you just hit me! — Hitbox attack system in Unity2D