public virtual void Play(MusicTrack track)
        {
            if (track.Size == 0)
            {
                Debug.LogError("Trying to play Musical Track: " + track.name + " but it has no clips in it");
                return;
            }

            if (coroutine != null)
            {
                StopCoroutine(coroutine);
            }

            coroutine = StartCoroutine(Procedure());

            IEnumerator Procedure()
            {
                IEnumerator Play(AudioClip clip)
                {
                    Source.Stop();

                    Source.clip = clip;

                    Source.Play();

                    yield return(Fade(track.Volume));

                    yield return(new WaitForSecondsRealtime(clip.length));
                }

                yield return(Fade(0));

                for (int i = 0; i < track.Size; i++)
                {
                    yield return(Play(track[i]));
                }

                while (true)
                {
                    yield return(Play(track.Last));
                }
            }
        }
Exemple #2
0
 public static void PlayMusic(MusicTrack track, bool repeating = true)
 {
     PlayMusic(track.ToString(), repeating);
 }