private IEnumerator ChangeMusicOneAndTwo()
{
AudioSource fadeOut = null, fadeIn = null;
if (audio1.volume > 0)
{
fadeOut = audio1;
fadeIn = audio2;
}
else if (audio2.volume > 0)
{
fadeOut = audio2;
fadeIn = audio1;
}
else//if both sources are silent (this shouldnt happen)
{ StopCoroutine("ChangeMusicOneAndTwo"); }
float fTimeCounter = 0f;
while (!(Mathf.Approximately(fTimeCounter, 1f)))
{
fTimeCounter = Mathf.Clamp01(fTimeCounter + Time.deltaTime);
fadeOut.volume = 1f - fTimeCounter;
fadeIn.volume = fTimeCounter;
yield return new WaitForSeconds(0.02f);
}
StopCoroutine("ChangeMusicOneAndTwo");
}
// one fades out, two fades in