Learning Unity — Adding Audio To Our Unity Projects

Joshua Nielsen
3 min readJul 6, 2021

In the last article, we learned how to make use of Unity’s post-processing features to add additional visual flair to our projects. In this article, we’re going to learn how to start working with audio in Unity.

The importance of audio

Audio has been an important part of video games since their inception. Back then, of course, the audio aspects of a game ranged from BEEP to BOOP, but nevertheless even those primitive audio cues gave important feedback to the players to tell them that something was happening.

This became especially important once video games began regularly having gameplay occurring outside of the range of the players’ vision. Think about an FPS, for example. If an enemy is firing at the player from behind, that is important information that the player would most likely discover from hearing the weapon fire.

Also, similar to film projects, a quality soundtrack can take a good game and make it legendary. I’m sure we can all think of our favorite tracks and replay them in our minds. Game audio encompasses both sound effects and soundtracks, and Unity audio system handles both.

Audio in Unity

Unity’s audio system is capable of many sophisticated features, not all of them obvious. It can play sound clips, of course, but it is also capable of simulating playing sounds in a 3D space. Additionally, it can also apply effects to the sounds, such as echoes and filters.

Unity is capable of importing most standard audio formats, and we can work with those assets in the Unity Editor in many of the same ways we can work with other sorts of assets. Support is there to drag and drop audio clips to appropriate destinations.

Also, Unity supports the recording of audio through the users’ microphones. Just imagine what new possibilities for gameplay this opens up!

Getting started in Unity

In order to create a simple example of how to use Unity’s audio system, we will first need a project open in the Unity Editor and we will need to import an audio asset into that project.

Once an audio asset is available, create a new, empty object in the project’s Hierarchy window. Within this empty object, add the Audio Source component.

The Audio Source component

With a game object created and an Audio Source attached, find the AudioClip option within the Audio Source component. Select the audio asset we added earlier to be the AudioClip. This can be done by dragging the asset into the AudioClip field. Finally, make certain that the Play On Awake option is selected.

Now just run the game and make certain your system’s audio is audible. The audio asset should be playing from the game immediately upon start. That’s all there is to it!

Now that we have some familiarity with the audio system in Unity, next time we’ll be seeing how we can get audio to play exactly when we want it to play. Until then, good luck and happy coding!

--

--