Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity: Difference between Audio Source, Audio Listener and Audio Clip

Tags:

unity3d

audio

I would like to play some sound effects in my Unity project.
I looked for a solution on the official website but I could not get the difference between an Audio Source, an Audio Listener and an Audio Clip.
Is it better to add them programmatically or to use an appropriate component?

Thank you in advance for your patience.

like image 525
Eminent Emperor Penguin Avatar asked Nov 07 '18 20:11

Eminent Emperor Penguin


People also ask

What are audio listeners in Unity?

The Audio Listener acts as a microphone-like device. It receives input from any given Audio Source in the scene and plays sounds through the computer speakers. For most applications it makes the most sense to attach the listener to the Main Camera.

What is an audio clip Unity?

Description. A container for audio data. An AudioClip stores the audio file either compressed as ogg vorbis or uncompressed. AudioClips are referenced and used by AudioSources to play sounds. See Also: AudioClip component in the Components Reference.

What is an audio source?

An AudioSource is a component that allows for sound to be played in your scene. It also holds the control options for the audio like Play Pause volume loop and all other properties and methods you need to control how the playback of your sounds work.

What is an audio clip?

Audio Clip means a contiguous sound recording excerpt of up to thirty (30) seconds in length taken from a single Authorized Track.


1 Answers

An AudioSource is a component that allows for sound to be played in your scene. It also holds the control options for the audio like Play Pause volume loop and all other properties and methods you need to control how the playback of your sounds work. This component also supports 3D audio, meaning the sound will come form the location of the GameObject it is on, like a persons mouth for example. Code examples and other properties/methods for AudioSource can be found in the documentation here

the asset type AudioClip is used by the AudioSource for playback. AudioClip contains the file you want to play back as either compressed ogg vorbis, or uncompressed. AudioClip also holds all information about that clip like the length and frequency. Full documentation on all methods and properties found here

You select what AudioClip the AudioSource plays by setting the AudioSource.clip property.

Finally you have the component AudioListener, that as the name suggest is what listens for the audio in your scene (that is played from an AudioSource). To be able to hear sounds in your scene you need an AudioListener (There is one by default on the main camera, and is limited to one per scene) and be in the range of your AudioSource. Just like AudioSource the AudioListener also has a volume property, but they are not the same. The volume property of the AudioListener dictates the volume for the entire game, where on an AudioSource it only dictates the volume for that specific instance. the full documentation expliaining all properties and methods can be found here

like image 90
Remy Avatar answered Sep 17 '22 17:09

Remy