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

房东的猫 提交于 2021-02-18 22:34:26

问题


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.


回答1:


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



来源:https://stackoverflow.com/questions/53197379/unity-difference-between-audio-source-audio-listener-and-audio-clip

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!