Coroutine seens not working...

Possible Duplicates:

Static IEnumerator!?

BCE0005: Unknown identifier: ‘StartCoroutine’.

Hi, I think this IEnumerator here, just don't run... Why?

class Joemerson
{
    static function Falar(numero : int)
    {
        Legenda.texto = "haha";
        Ler(numero);
    }

    private static function Ler(n : int)
    {
        Legenda.texto = "hehe";
        ...
        while(something)
        {
            yield WaitForEndOfFrame();
        }
    }
}

"Legenda.texto" change the text of a GUItext, and with the change, another script show it at the screen in the same time...

The output is: haha

So, the IEnumerator just don't run!

Help!

Stop the hell posting a milion questions on the same topic and stop mark answers that doesn't work as solved! Read the FAQs!!! http://answers.unity3d.com/questions/45330/static-ienumerator http://answers.unity3d.com/questions/45348/bce0005-unknown-identifier-startcoroutine

Quite a reaction. But the point is being made.

1 Answer

1

As i wrote already in my comment on mike's answer in your other question. Coroutines only work in MonoBehaviour instances. If the coroutine itself is static it have to be invoked via StartCoroutine of any script instance.

Sorry, really don't saw the comments...

Coroutines do work being static though. You just can't chain them. And they don't need to be a instance method, it just need to be called using StartCoroutine from one (in JS this seems to be implicitly called).

Well, you're right (just tried it ;)) static works but you still need a script instance to use StartCoroutine. I've answered the very first question (which was in C#)... http://answers.unity3d.com/questions/41355/ienumerator-solution

Ohh, and even in JS you need to use StartCoroutine at least for static coroutines. I tried it without and i got no errors but the function simply doesn't get called. The problem of this question is how to enable you to invoke a coroutine from a static function that is accessible from everywhere (without using StartCoroutine when you want to call it).

Well, I don't know how JS people would do it. I would do with a extension method in C#. But you could always pass a host script that kicks the coroutine going (since coroutines belong to scripts).