protected void FadeOut() { /* If still fading in, stop */ if (!ReferenceEquals(fadeIn, null)) { StopCoroutine(fadeIn); } AudioSource old = this.GetComponent <AudioSource>(); StartCoroutine(Fade(old, old.volume, 0f, fadeDuration, true)); if (owner == this) { owner = null; } }
private Coroutine fadeIn; /* The coroutine fading in the current owner */ void Start() { /* A new audio source has spawned. Perform a cross fade */ DontDestroyOnLoad(this.gameObject); /* Begin fading out the previous owner if one exists */ if (owner != null) { owner.FadeOut(); } /* Set this as the new owner and begin fading in */ owner = this; AudioSource toPlay = this.GetComponent <AudioSource>(); float endVolume = toPlay.volume; toPlay.volume = 0f; toPlay.Play(); fadeIn = StartCoroutine(Fade(toPlay, 0f, endVolume, fadeDuration)); }
public void Start() { fade = GameObject.FindGameObjectWithTag("Music").GetComponent <CrossFadeAudio>(); }
// Start is called before the first frame update void Start() { fade = GameObject.FindGameObjectWithTag("Music").GetComponent <CrossFadeAudio>(); fade.CrossFade(menu, 1, 3); }