I am writing a game with looping music. Some of the songs start and loop back to the very beginning of the clip, and these loop fine. Some of the other songs have in intro portion which plays first before entering the looping portion of the song, so the intro portion is not heard when the song loops. Here is some code:
void Start() {
source = GetComponents<AudioSource>()[0];
introSource = GetComponents<AudioSource>()[1];
activeSong = song.midnight;
source.clip = midnightBodyClip;
introSource.clip = midnightIntroClip;
introSource.Play();
source.PlayScheduled(AudioSettings.dspTime + introSource.clip.length);
DontDestroyOnLoad(gameObject);
}
The problem is that I easily notice that the body clip starts a split second too early, causing the two to overlap briefly. I tried early to have Update() check for when the intro clip ends, but understandably there is a gap between the clips in this case. Why is PlayScheduled starting too early if I’m using the exact length of the intro clip? I don’t want to use any plugins to fix this, but it’s okay if the solution is complicated.