I currently have 2 Background music audio clips which I want to play immediately one after another (intro followed by a loop when the intro is done playing).
However, no matter what I try, there seems to me a noticeable gap when transitioning from one track to an other… Is there any way around this (other than crossfading)
Below is what I have come up with so far:::
///////////////////////////////////////////////////////////
private static bool loopStarted = false;
public AudioClip backGroundMusic_Intro;
public AudioClip backGroundMusic_Loop;
//--Separate audio sources to try and avoid loading delays
private AudioSource bgA;
private AudioSource bgB;
void Awake(){
bgA = gameObject.AddComponent<AudioSource>();
bgB = gameObject.AddComponent<AudioSource>();
bgA.clip = backGroundMusic_Intro;
bgB.clip = backGroundMusic_Loop;
bgA.loop = false;
bgB.loop = true;
bgA.Play ();
}
// Fixed Update called multiple times per frame
void FixedUpdate () {
if(loopStarted == false && !(bgA.isPlaying)){
bgB.Play();
Destroy (bgA);
loopStarted = true;
}
}
///////////////////////////////////////////////////////////