Decrease Volume

I have a music in my game and I want it to decrease the volume at one point, and reach to 0 so you don’t hear music. How can I do that?

It sounds like you already have the music playing, so something like this should get you started. It should be pretty trivial to expand to fade the other way/etc :slight_smile:

public AudioSource source; // Assign in editor/etc
public float fadeTime = 1; // fade time in seconds

public FadeSound() { 
    if(fadeTime == 0) { 
        source.volume = 0;
        return;
    }
    StartCoroutine(_FadeSound); 
}

IEnumerator _FadeSound() {
    float t = fadeTime;
    while (t > 0) {
        yield return null;
        t-= Time.deltaTime;
        source.volume = t/fadeTime;
    }
    yield break;
}

If you get the AudioSource that the current AudioClip is playing on, the audio source will expose the volume that you can set as a float.

AudioSource.volume sets the volume for an audio source. Values range from 0 to 1.