How to fade out music when scene is loaded using C#
So I'm trying for fade out my menu music using c# when the next scene loads, any ideas or starts?
Answer by spooneystone · Oct 29, 2015 at 09:24 PM
Try
public audiosource audio
audio.volume = mathf.lerp(audio.volume, 0 , time.deltatime); Dontdestroyonload(game object);
Thanks I will, if anyone else wants to chime in go for it.
Note that loading may block the main thread and you may not be able to fade the audio neatly. You could possibly make more accurate fades implementing OnAudioFilterRead which runs on another thread.
This is still not working:
using UnityEngine; using System.Collections; public class AudioFade : $$anonymous$$onoBehaviour {
public AudioSource $$anonymous$$enu$$anonymous$$usic; GetComponent().volume = mathf.lerp(GetComponent().volume, 0 , time.deltatime); Dontdestroyonload(this.gameObject); }