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.
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.
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.
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.
Audio Clip means a contiguous sound recording excerpt of up to thirty (30) seconds in length taken from a single Authorized Track.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With