AudioSource Component Reference
property
property | illustrate |
---|---|
Clip | Audio resources |
Volume | Volume size |
Mute | Whether to mute |
Loop | Whether to cycle |
Play on load | Whether to play immediately after loading |
preload | Whether it is preloaded when it is not played |
Audio Source: Sound component. It needs to be used with Audio Listener, Main Camera will have Audio Lisetener by default.
Audio Clip: Sound clip. Specifies the audio file to be played.
Play On Awake: Play starts playing after the game starts running.
Mute: Mute.
Loop: Whether to play loop.
Volume: Volume.
Spatial Blend: Space blending, setting whether the sound is 2D or 3D. The distance between 3D sound and the source will affect the size of the sound you hear, and 2D sound will not affect.
Commonly used methods to start playback, stop playback, and pause playback:
public class Test { public AudioSource audioSource; private void Start() { ();//Start playback ();//Stop playback ();//Pause playback } }
(AudioClip,Vector3,float): Specify a position in the world coordinate system to play sound clips.
AudioClip: A sound clip that needs to be played.
Vector3: The location where the sound clip is played.
float: volume.
When playing sounds, an object named "One shot audio" will be automatically generated, and AudioSource and corresponding audioclips are automatically added. When playing multiple sounds at the same time, multiple objects of the same name will be generated. The playback of each sound will not affect each other. However, the disadvantage is that you can only set the volume and position, and you cannot set the loop. After the playback is completed, One shot audio will be automatically destroyed.
Summarize
The above is the Audio Source component and related API introduced by the editor. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!