- Home /
Question by
jbalzer · Feb 16, 2011 at 12:51 AM ·
javascriptclassyieldwaitforseconds
Can I not use yield waitForSeconds in a class function?
I have a class like this:
class ignore { var howLong:float = 0;
function ignore () {}
function timedIgnore(){
Debug.Log("ignoring for " + howLong + " seconds");
yield WaitForSeconds (howLong);
Debug.Log("done ignoring...");
}
}
I have this in another game object / script / function:
var iggy = new ignore();
iggy.howLong= 5;
iggy.timedIgnore();
And nothing happens. The Debug.Logs don't appear. If I remove the yield line, both Debug.Logs appear, but, obviously, I want a timer here...
So, is the yield not allowed in a class like this, or am I doing something else wrong?
thanks in advance!
Comment
Best Answer
Answer by Eric5h5 · Feb 16, 2011 at 12:59 AM
You have to use StartCoroutine explicitly when starting coroutines from classes like that.
StartCoroutine(iggy.timedIgnore());
jajaja sorry, never new that you can use class in javascript I think it was for C# and java and others :P, but its true that it also work if you quit the class.
@Uriel: JS in Unity isn't really JS, it's more like JScript.NET.