Wait() is not working for me!

Ok, so I have made a cutscene in unity and I used this code;
var hold : int = 660; //Set this for how long your animation is

function Update () {
 
//Play animation
 
wait();
 
Application.LoadLevel(2); //Your scene
 
}
 
function wait () {
 
yield WaitForSeconds ((hold));
 
}

LightSource helped me, but it doesn’t play the cutscene, it just skips to the game! I am very much of a noob, so be easy on me. :3
Please help!

2 Answers

2

Try something like this:

var hold = 660;

function Start () {
	wait();	
}

function wait () {
	//play your cutscene here
	yield WaitForSeconds(hold);
	Application.LoadLevel(2);
}

Add the code to make your cutscene play where the comment is, I tested this with an audio clip and it worked, hopefully you have success!

Scribe

OH MY GOD YOU ARE AMAZING! THANK YOU x100! If you were here I'd give you a hug!

There’s no point to the wait function, since it just does WaitForSeconds. So, get rid of it and just use WaitForSeconds directly instead. You can’t make Update into a coroutine, so move any code that needs WaitForSeconds out of Update.

Ummmm... I'm sorry for not understanding, it's just that I am a complete javascript noob, but I'll try what you said, though I don't get what a coroutine is, I'll try to figure it out. I think I broke it; var hold : int = 11; //Set this for how long your animation is function Update () { //Play animation WaitForSeconds(11); Application.LoadLevel(2); //Your scene } function wait(hold) { yield WaitForSeconds ((hold)); }