Audio in Unity

Eyas
9 min readOct 16, 2022
“Blue Condenser Mic”, photo by Kelly Sikkema

Let’s talk about all the ways you can play and manage audio in your game. Audio makes an interesting topic; it’s relatively easy to get some audio playing in your game, but it’s often unclear how to move from the simplest use case to a slightly more complex one.

This is Unity for Software Engineers, a series for those seeking an accelerated introduction to game development in Unity.

AudioClip, AudioSource, and AudioListener

Let’s start with the three primary constructs involved with playing audio:

  • An Audio Clip (in code AudioClip) is an asset representing a sound file.
  • An Audio Source (in code AudioSource) is a component on a GameObject. An Audio Source can play Audio Clips at the object’s location for any listeners to hear.
  • An Audio Listener (in code, AudioListener) is a component on a GameObject representing the object receiving (i.e., listening to) audio.
An Audio Source component allows the user to set a clip, and many other properties, including Play On Awake, Loop, and a per-source volume.

There should be one Audio Listener per scene. Typically, the Audio Listener component will be attached to the Main Camera object by default. You have full control over changing that, but putting your Audio Listener on…

--

--

Eyas

Software Engineer living in Brooklyn, NY. MIT Computer Science S.B. ’13, M.Eng. ‘14. From Amman, Jordan. Interested in politics, current affairs, and technology