Audio Extensions

Play Clip

This plays the specified AudioClip on the AudioSource.

AudioSource audioSource = GetComponent<AudioSource>();

audioSource.PlayClip(audioClip);

Set Volume

This sets the volume of the AudioSource to 0.5 (50% of maximum volume).

AudioSource audioSource = GetComponent<AudioSource>();

audioSource.SetVolume(0.5f);  

Get Volume

This gets the volume of the AudioSource with a default value of 0.0f.

AudioSource audioSource = GetComponent<AudioSource>();

audioSource.GetVolume();   

Set Pitch

This sets the pitch of the AudioSource to 0.5.

Set 3D Properties

This sets the 3D properties of the AudioSource with a 1f value of minDistance, 500f of maxDistance, and 1f of spatialBlend.

Pause Clip

This pauses the currently playing audio clip.

Resume Clip

This resumes playback of the audio clip from where it was paused.

Stop Clip

This stops the currently playing audio clip.

Fade Out

This starts fading out the audio over a duration of 2 seconds, gradually decreasing the volume to 0 and stopping the playback.

Fade In

This starts fading in the audio over a duration of 2 seconds, gradually increasing the volume to 1.

Crossfade

This crossfades the current audio clip with the given audio clip over a duration of 2 seconds, gradually decreasing and increasing the volume from 0 to 1.

Last updated