IEnumerator CrossFade_(AudioSource audioIn, StemPlayer stemsOut, float xfadeTime) { // Waits until nothing is fading. while (isFading) { yield return(null); } isFading = true; // Fades out the stem player that is supposed to stop playing. stemsOut.Stop(xfadeTime); // Fades in the audio source that is supposed to start playing. fader.StartAndFadeIn(audioIn, xfadeTime, mainThemeVolume); // Waits for the fade. yield return(new WaitForSeconds(xfadeTime)); isFading = false; }
// Stops the main loop music // All ongoing coroutines and invokes will be cancelled. public void StopMainLoopMusic(float fadeTime = 0.0f) { CancelInvoke(); StopAllCoroutines(); mainLoopMusic.Stop(fadeTime); }