public void StopBgm(float timeFade = 0f) { if (timeFade <= 0f) { bgmSource.Stop(); subBgmSource.Stop(); } else { StartCoroutine(FadeOutBgm(timeFade)); } }
private IEnumerator CrossFadeBgm(AudioClip clip, float duration) { isCrossFading = true; BgmSource tmp = bgmSource; bgmSource = subBgmSource; subBgmSource = tmp; bgmSource.clip = clip; bgmSource.time = 0f; bgmSource.Play(); float time = 0f; while (time < duration) { float t = time / duration; bgmSource.volume = Mathf.Lerp(0f, bgmVolume, t); subBgmSource.volume = Mathf.Lerp(bgmVolume, 0f, t); yield return(null); time += Time.unscaledDeltaTime; } bgmSource.volume = bgmVolume; subBgmSource.Stop(); isCrossFading = false; }
private void InitializeBGM() { stageReactiveProperty.Subscribe((stage) => { if (stage >= BgmClips.Length) { return; } BgmSource.Stop(); BgmSource.clip = BgmClips[stage]; BgmSource.Play(); }); }
/******************** * Functions for bgm * ********************/ public bool PlayBgm(AudioClip clip, float timeCrossFade = 0f) { if (isCrossFading) { return(false); } isBgmLoop = false; if (timeCrossFade <= 0f) { bgmSource.Stop(); bgmSource.volume = bgmVolume; bgmSource.clip = clip; bgmSource.time = 0f; bgmSource.Play(); } else { StartCoroutine(CrossFadeBgm(clip, timeCrossFade)); } return(true); }
public void StopBgm() { BgmSource.Stop(); }
public void PlayBgm() { BgmSource.Stop(); BgmSource.Play(); }
public void PlayBgm(AudioClip clip) { BgmSource.Stop(); BgmSource.clip = clip; BgmSource.Play(); }