Hello,I've been coding for a bit of time but I have never been able to get yield to work for me. It doesn't work. This is one of the scripts that needs to yield.
#pragma strict
var VictoryTheme : AudioClip;
function OnTriggerEnter (info : Collider)
{
if(info.tag == "Player")
{
GameMaster.StopAllAudio();
AudioSource.PlayClipAtPoint(VictoryTheme, transform.position);
Time.timeScale = 0;
yield WaitForSeconds(3.5f);
Time.timeScale = 1;
GameMaster.CreateMusic = true;
GameMaster.MusicManager.GetComponent.().enabled = false;
Application.LoadLevel ("MainMenuPorted");
}
}
The script happens when the player collects and item. It ends the level and sends them back to the menu. I want it to play a victory jingle and then load the next level, but it just yields forever and never ends. Thank you in advance.
Edit: I moved it to a separate function and I called it by start coroutine. But it works better now but now it just skips over the actual yield. Or in other words, it works but it doesn't yield. Here is the new code.
#pragma strict
var VictoryTheme : AudioClip;
function OnTriggerEnter (info : Collider)
{
if(info.tag == "Player")
{
StartCoroutine("Stop");
Debug.Log("Finished the yield");
Time.timeScale = 1;
GameMaster.CreateMusic = true;
GameMaster.MusicManager.GetComponent.().enabled = false;
Application.LoadLevel ("MainMenuPorted");
}
}
function Stop()
{
GameMaster.StopAllAudio();
AudioSource.PlayClipAtPoint(VictoryTheme, transform.position);
Time.timeScale = 0;
yield WaitForSeconds(VictoryTheme.length); // It skips past this line of code
}
thank you for the help.
↧