My journey becoming a Unity game developer: Audio Manager: Play the audio clips with stable sound quality

Rhett Haynes
4 min readNov 23, 2021

Objective: Create an Audio Manager object and script to play the audio clips assigned to each Voice Over Trigger game object producing stable sound quality.

Voice Triggers play audio clips using the Audio Manager.

As we play the game, we will notice that when the player walks through each Voice Over Trigger game object, the sound starts off with clear quality of Oliver speaking to Darren. However, as Darren moves further away from the Voice Over activated trigger objects, Oliver’s voice begins to trail off in the distance. This is happening because we assigned the audio clips to play from the Main Camera’s original position at the point where the voice trigger game objects are located. Therefore, as the Main Camera moves further away from the Voice Over triggers, Oliver’s voice will keep sounding muffled. We need to fix this problem by using an Audio Manager.

The Audio Manager will be used to play any audio clips using this manager and the Audio Source assigned to a game object to play in a 2D Spatial area instead of the 3D areas the audio clips are playing in currently. Also, we will be able to tweak the volume settings in the Audio Source using the Audio Manager as well.

Create an Audio Manager using an Empty game object. Set its Transform positions to zero. Create another Empty game object name VO for voice over. Set its Transform positions to zero as well. Place the VO game object as a child inside of the Audio Manager game object. Add an Audio Source component to the VO object. Create a new Audio Manager script name AudioManager, and attach it to the Audio Manager game object.

Audio Manager game object and script created.

Inside the AudioManager script we will use the Singleton pattern. Create a new static variable Type AudioManager name instance for the Audio Manager. Then, create a new static property name Instance to retrieve the Audio Manager instance variable. In its Getter check if the instance is NULL, if it is send a Debug.LogError message notifying the Audio Manager is NULL. If it’s not, return the instance. Use the Awake() function to set the instance to This script.

Audio Manager script created using the Singleton pattern.

Next, we want to create a public variable with a Type Audio Source name voiceOver to be a place holder for the VO game object since it has the Audio Source attached to it. Place this variable above the Awake() function.

In the Audio Manager game object, add the VO game object into the Voice Over slot under the Audio Manager script component.

Voice Over game object added to Voice Over script component.

Now create a method name PlayVoiceOver() which will have an Audio Clip name clipToPlay passed in as a parameter. Assign the voiceOver clip to be the clipToPlay passed in. Then, Play the clip through the voiceOver Audio Source.

Play Voice Over method created to play audio clips passed in.

In the Voice Over Trigger script, we originally set the audio clips to be played from the point where the player passed through the Voice Over Trigger object at the Main Camera’s position.

Original script for Darren’s voice over triggers as he move through the room.

Instead, we’re going to change the Audio Clip variable name from audioClip to clipToPlay. Then inside of the IF its the Player Tag condition, delete the previous line of code and replace it calling the Audio Manager script’s Instance property to use the PlayVoiceOver() method passing in the clipToPlay Audio Clip being used from each Voice Over Trigger.

Changed variable’s name and used Audio Manager’s Play Voice Over method to play audio clip.

In the VO game object’s Audio Source component, we will turn off the Play on Awake since we don’t want the audio clip to play until its been triggered. Turn the Volume down to 50% because the audio clip’s sound was too loud. Make sure the Spatial Blend is set to 2D as we want the clips to play all around and not at a 3D position activated in the game.

Voice Over game object’s audio source settings adjusted.

Since we changed the variable’s name inside of the Voice Over Trigger script, we must check to make sure the VO Triggers game objects audio clips are assigned to each of them.

Voice Over Triggers audio clips reassigned after variable’s name changed.

When we play the game now, as the player enters each VO Trigger game object, the audio clips will play with a consistent and clear sound quality to them.

Voice Triggers play using the Audio Manager with the sound quality stabilized.

Next time we will add some ambient background music to the game.

--

--