public void PlayBackgroundNoise(BackgroundNoise type) { if (type == currentType) { return; } ForcePlayBackgroundNoise(type); }
private AudioSource GetAudioSource(BackgroundNoise type) { switch (type) { case BackgroundNoise.Basement: return(basementSource); case BackgroundNoise.Outdoors: return(outdoorSource); default: Debug.LogError("Unrecognized background noise type: " + type); return(null); } }
private void ForcePlayBackgroundNoise(BackgroundNoise type) { currentType = type; previousSource = currentSource; currentSource = GetAudioSource(currentType); if (previousSource != null) { StartCoroutine(FadeAudioSource.StartFade(previousSource, crossFadeDurationSec, 0)); } if (currentSource != null) { StartCoroutine(FadeAudioSource.StartFade(currentSource, crossFadeDurationSec, volume)); } }