So I have a javascript game I am redoing and almost done. In one of the functions I call the coroutine to adjust the audio. It does this ok, but I can’t set the length. How do you do that.
- So looking at the script, I have a variable at the top 'linkToMusic;. This is set in the inspector to another game object that holds the msic.
- I then (in a function) call the coroutine ‘FadeAudioOut();’.
- In the corotuine, I am trying to fade out the music over a 1 second real time period to match up with the video fade out to back.
So basically, it’s just how do I set the time in the coroutine to 1 second fade to 0 or even a 2 second fade to 0?
///////////////////////////////////////////////////////
var linkToMusic : GameObject;
///////////////////////////////////////////////////////
//Fade Audio Out
FadeAudioOut();
//////////////////////////////////////////////////////
//Audio fade out coroutine
function FadeAudioOut()
{
while (linkToMusic.GetComponent.<AudioSource>().volume > 0)
{
linkToMusic.GetComponent.<AudioSource>().volume -= Time.deltaTime;
yield;
}
}