Unity:音频源,音频监听器和音频剪辑之间的区别 [英] Unity: Difference between Audio Source, Audio Listener and Audio Clip
问题描述
我想在Unity项目中播放一些音效.
我在官方网站上寻找解决方案,但无法获得音频源,音频监听器和音频剪辑之间的区别.
以编程方式添加它们还是使用适当的组件更好?
预先感谢您的耐心等候.
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.
推荐答案
AudioSource
是组件,允许在场景中播放声音.它还包含音频的控制选项,例如 Play
Pause
volume
loop
以及您需要的所有其他属性和方法控制声音的播放方式.该组件还支持3D音频,这意味着声音将来自其所在的 GameObject
的位置,例如人的嘴巴. AudioSource
的代码示例和其他属性/方法可以在文档此处找到
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
资源类型 AudioClip
被 AudioSource
使用进行播放. AudioClip
包含要以压缩的ogg vorbis或未压缩的格式播放的文件. AudioClip
还保存有关该剪辑的所有信息,例如 length
和 frequency
.在此处
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
通过设置 AudioSource.clip
属性,选择 AudioSource
播放的 AudioClip
.
You select what AudioClip
the AudioSource
plays by setting the AudioSource.clip
property.
最后,您有了组件 AudioListener
,顾名思义,它是对场景中音频的监听(从 AudioSource
).为了能够听到场景中的声音,您需要一个 AudioListener
(默认情况下,主摄像机上只有一个,并且每个场景仅限于一个)并且位于您的 AudioSource
的范围.就像 AudioSource
一样, AudioListener
也具有 volume
属性,但它们不同. AudioListener
的 volume
属性决定了整个游戏的音量,而在 AudioSource
上,它仅决定了该特定实例的音量.可以在此处
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
这篇关于Unity:音频源,音频监听器和音频剪辑之间的区别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!