Ejemplo n.º 1
0
 public virtual void PauseMusic()
 {
     if (CurrentMusicAudioSource != null)
     {
         CurrentMusicAudioSource.Pause();
     }
 }
Ejemplo n.º 2
0
        public void FadeMusic(float volume, float duration)
        {
            // currentMusicAudioSource may be null
            if (CurrentMusicAudioSource == null)
            {
                return;
            }

            if (_muteMusic)
            {
                CurrentMusicAudioSource.Pause();
                return;
            }

            if (!CurrentMusicAudioSource.isPlaying)
            {
                CurrentMusicAudioSource.Play();
            }

            if (_musicFadeOutTweener != null)
            {
                _musicFadeOutTweener.Kill();
            }

            if (duration <= 0)
            {
                CurrentMusicAudioSource.volume = volume;
                if (volume < .1f)
                {
                    CurrentMusicAudioSource.Pause();
                }
            }
            else
            {
                _musicFadeOutTweener = DOTween.To(() => CurrentMusicAudioSource.volume, (val) => CurrentMusicAudioSource.volume = val, volume, duration).OnComplete(() => this.DoneMusicFade(CurrentMusicAudioSource));
            }
        }