// Plays music for the 'level' level public void PlayLevelMusic(string level) { // Get what music to play for this level string levelMusic = GetLevelMusic(level); // Do a bunch of checks that currently playing music and the music you want to play // exist. And that they are not the same (to prevent song restart on restart of the room) if (musicDict.ContainsKey(levelMusic) && musicDict.ContainsKey(currentLevelMusicName) && (!musicDict[currentLevelMusicName].isPlaying || currentLevelMusicName != levelMusic)) { // Stop previously playing music if (currentLevelMusicName != levelMusic) { musicDict[currentLevelMusicName].Stop(); currentLevelMusicName = levelMusic; } // Play new music StopAllCoroutines(); StartCoroutine(AudioEffects.Fade( musicDict[currentLevelMusicName], 0.0f, _musicVolume, 0.5f) ); } }
// Fadeout currently playing level music public void FadeOutLevelMusic() { if (musicDict.ContainsKey(currentLevelMusicName)) { StopAllCoroutines(); StartCoroutine(AudioEffects.Fade( musicDict[currentLevelMusicName], musicDict[currentLevelMusicName].volume, 0.0f, 0.5f) ); } }