Fading Audio Source

Attaching the following script to your AudioSource allows you to fade between audio clips instead of changing them instantly. Set FadeSpeed to the desired volume change per second when fading, and FadeOutThreshold to the volume to end the previous clip at.

Calling the Fade method of the FadingAudioSource will


 * fade out the current clip and fade in the specified one, after, if the audio source is enabled and playing.
 * fade in the specified clip immediately, if the audio source is enabled and not playing.
 * fade in the specified clip as soon as the audio source gets enabled, if it is not enabled.