private IEnumerator ChangeMusicTwoAndThree()
{
AudioSource fadeOut = null,fadeIn = null;
if (audio2.volume > 0 )
{
fadeOut = audio2;
fadeIn = audio3;
}
else if (audio3.volume > 0)
{
fadeOut = audio3;
fadeIn = audio2;
}
else//if both sources are silent (this shouldnt happen)
{StopCoroutine("ChangeMusicTwoAndThree");}
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("ChangeMusicTwoAndThree");
}
///fades three to one