Immersion Starts with Sound

Adding Background Music in Unity

Now that we’ve added post processing to make our game look like a AAA title we need to round it out with sound! If we really want to immerse our players into our game sound plays a huge part in it! From the subtle background sounds of birds and foot steps in a jungle based first-person shooter to the sound of that particularly nasty lock puzzle hitting the ground after you’ve solved it in your favorite escape room VR game, sound can be just as important for a players immersion as the visuals they are presented. In our space shooter we are going to start with adding some background music to set the mood!

Audio Components

Audio Listener
Audio Listener

For our purposes there are two important things to know about our Audio Listener component. The first is that it is supplied to us out of the box by Unity and it is attached to the Main Camera by default. The second is that we are only supposed to have one Audio Listener in a scene. If we duplicate our Main camera, like we did when we created a second camera for objects that we wanted to exclude from post processing, then we need to remember to remove the duplicated Audio Listener component or Unity will give you warnings.

Duplicate Audio Listener Error
Duplicate Audio Listener Error

The next component we need is an Audio Source component. This component gives us most of the functionality we use when controlling our Audio including playback and looping.

Audio Source
Audio Source

The last component is an Audio Clip which is the class that represents the specific sound that we are playing through our Audio Source.

Audio Clip
Audio Clip

Adding background music

Add Audio Manager
Add Audio Manager

Lastly, we can check the loop and play on awake options on our Audio Source and assign our audio file in the Audio Clip property.

Add Audio Clip
Add Audio Clip

Now when we play our game we should hear our snazzy game background music. You may need to adjust the volume on the Audio Source component of the music is loud.

Next Time!

Unity Game Developer, Software Engineer, Gamer, Musician, and Father. Christopher is a creative that enjoys a challenge and loves coding.

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