- Home /
Load Level when dead for 1 second
This code gives me the Update() Cannot be a courotine......how do i fix this?
var numberTimesDead:int = 0;
var timesCanDie:int = 1;
function Update() {
if(numberTimesDead == timesCanDie){
yield WaitForSeconds(1);
Application.LoadLevel(0);
}
}
Answer by MakakWasTaken · Sep 08, 2015 at 06:25 PM
var numberTimesDead:int = 0;
var timesCanDie:int = 1;
function Update() {
if(numberTimesDead == timesCanDie) {
Coro();
}
}
public var b : bool = false;
public function Coro() {
if (!b) {
b = true;
yield WaitForSeconds(1);
Application.LoadLevel(0);
}
}
This should do the trick, I must admit it has been some time since I programmed in unityscript. As far as I remember you should have to call the coroutine with StartCoroutine as in C#, but if the above doesn't work it should be
StartCoroutine("Coro");
instead of
Coro();
Answer by Erdroy · Sep 08, 2015 at 06:22 PM
It should be sth. Like this:
In Update func.
if(numberTimesDead == timesCanDie)
{
StartCoroutine(LoadNewLevel(0));
}
function LoadNewLevel (index : int)
{
yield WaitForSeconds(1);
Application.LoadLevel(index);
}
And... It should now work.
Your answer
Follow this Question
Related Questions
lock a target after a few seconds 1 Answer
Invoke repeating OR coroutine with WaitForSeconds? 1 Answer
Yield WaitForSeconds doesn't work, give syntax error 1 Answer
yield WaitForSeconds compatibility? 0 Answers
Wierd issue with Coroutines? 2 Answers