void Update()
{
if (GameController.sharedInstance().isGamePause)
{
audioSource.Pause();
}
if (GameController.sharedInstance().isGamePause == false )
{
if (audioSource.isPlaying == false)
audioSource.Play();
}
if (time.getCurrentTime() == 83 && state != STATE_CLIP2 )
{
state = STATE_CLIP2;
}
if(time.getCurrentTime() == 82 && isFadeOut)
{
audioSource.clip = clip2;
audioSource.volume = intialVolume;
audioSource.Play();
}
if (state == STATE_CLIP2 && (time.getCurrentTime() > 83 || GameController.sharedInstance().isPowerUpSelected))
{
audioSource.Pause();
audioSource.volume = intialVolume;
audioSource.clip = clip1;
audioSource.Play();
state = STATE_CLIP1;
GameController.sharedInstance().isPowerUpSelected = false;
isFadeOut = false;
}
if (state == STATE_CLIP1 && (time.getCurrentTime() < 83 || GameController.sharedInstance().isPowerUpSelected))
{
fadeOutMusic(audioSource);
isFadeOut = true;
audioSource.Pause();
audioSource.volume = intialVolume;
audioSource.clip = clip2;
audioSource.Play();
state = STATE_CLIP2;
GameController.sharedInstance().isPowerUpSelected = false;
isFadeOut = false;
}
if(time.getCurrentTime() == 82 && !isFadeOut)
{
fadeOutMusic(audioSource);
isFadeOut = true;
}
}
private void fadeOutMusic(AudioSource audioSource)
{
while (audioVolume >= 0.1)
{
audioVolume -= 0.1f * Time.deltaTime;
audioSource.volume = audioVolume;
}
}