Audio Source components and related APIs, sourceapi
Audio Source:Sound components. It must be used with the Audio Listener. The Main Camera will have the Audio Lisetener by default.
Audio Clip:Sound fragment. Specifies the audio file to be played.
Play On Awake:The game starts playing after it starts running.
Mute:Mute.
Loop:Whether to play cyclically.
Volume:Volume.
Spatial Blend:Space mixing, set the sound to 2D or 3D sound. The distance between a 3D sound and the sound source will affect the size of the sound to be heard, and the 2D sound will not be affected.
Common Methods for starting, stopping, and pausing a video are as follows:
1 public class Test 2 {3 public AudioSource audioSource; 4 5 private void Start () 6 {7 audioSource. play (); // start playing 8 audioSource. stop (); // Stop playing 9 audioSource. pause (); // Pause playing 10} 11}
AudioSource. PlayClipAtPoint (AudioClip, Vector3, float ):Specifies a position in the world coordinate system to play a Sound clip.
AudioClip: the audio clip to be played.
Vector3: the position of the video clip.
Float: volume.
Use AudioSource. playClipAtPoint automatically generates an object named "One shot audio" and adds AudioSource and audioclip, multiple objects with the same name are generated when multiple sounds are played at the same time. Playing of each sound does not affect each other. However, the disadvantage is that only the volume, position, and loop can be set. After playing is complete, one shot audio is automatically destroyed.