Audio Listener/Source

From ETC Public Wiki
Jump to: navigation, search

Note:This will not cover audio scripting--please refer to the "Sound" section under "Programming".

Extra Resources:


Audio Listener

Definition: The Audio Listener is essentially a microphone for the game--all audio that occurs in the game/world will be interpreted from the perspective of whatever object is appointed as the listener. For instance, first person shooter games normally have the audio listener attached to the game's main camera so that all sound will be interpreted by what is essentially the perspective of the play. In fact, most games have the audio listener set to the main camera.


Setting an Audio Listener

  1. Practically nothing! By having a Main Camera, you will already have access to the audio listener, as main cameras are added with an audio listener by default. There are no settings or alternate properties to the audio listener. Note: Unity will only allow one audio listener per scene.


Audio Source

Definition: The Audio Source is any object in the game/world that plays a sound file. Unlike the Audio Listener, the audio source does have a hefty sum of properties and settings for you to tool around with, which we will get to later on in this page.


Setting an Audio Source

See Fig. 1

  1. Select the desired game object to be the audio source in the Hierarchy window. File:AudioSourceInspector.png
  2. Select Audio Source by going to Component -> Audio -> Audio Source.
  3. In the Inspector window under the newly created audio source tab, the first category, Audio Clip, is where you can drag and drop audio clips from the Project folder to set the audio source to that sound file. Once a sound file is dropped, both the name of the file and a note on whether the clip is 3D or 2D will be displayed.
  4. From here on out, everything you do will be optional--the audio source has already been established on the object. Looking at the audio source tab in Inspector, there are a few basic parameters for you to control:
  • Mute - Checking this will mute the sound--simple as that.
  • Bypass Effects - Checking this will have the sound play without any of Unity's audio effects--if you applied any beforehand.
  • Play on awake - Checking this box will cause the sound to play as soon as the game/world begins--this is good for ambience or any sound that will be playing constantly throughout the scene. Note: Unchecking this box means that the sound will play conditionally according to the game's script. To learn how to script audio within unity, refer to the programming section of the tutorial.
  • Loop - Checking this will loop the file from start to finish--also pretty straightforward.
  • Priority - As it sounds, the slider determines which sounds will be eliminated if all of the game's sound channels are in use. The values go from 0 to 255--with 0 being the highest priority and 255 being the lowest. In general, it's good to have background music be 0 so that it never gets taken out of the experience.
  • Volume - Self explanatory.
  • Pitch - Also self explanatory except affecting the pitch will also affect the speed of the clip. It's a good idea to control pitch in a digital audio workstation of choice, as you will have control of the pitch of the audio file without affecting the speed. If affecting both speed and pitch is your thing, though, by all means use this feature.
  • Pan 2D - This is located under the 3D Sound tab. This will control how a 2D sound is panned between the left and right channels. Fun Fact: Pan 2D can be mixed together with a 3D sound for some interesting results.

Note: Keep in mind that all of these settings can be automated via scripting. So, for instance, if you wanted certain sounds to be shifted in priority, muted, or pitch shifted during the game experience, then it can all be done via scripting. Again, refer to the programming portion of this tutorial on how.