- Home /
Question by
Martian-Games · Sep 30, 2012 at 06:31 PM ·
waitforsecondscoroutines
Javascript function with coroutine fails when called from C#
Why are Javascript functions ignored whenever a C# script calls any Javascript function containing a WaitForSeconds() coroutine? (The Javascripts are compiled first).
[CODE]
// C#:
void StartGame(){
jsScript.test ();
}
// jsScript.js:
function test(){
print("TEST IN");
yield WaitForSeconds(1);
print("TEST OUT");
}
Comment
Best Answer
Answer by Eric5h5 · Sep 30, 2012 at 06:44 PM
You need to use StartCoroutine when starting coroutines in C#.
I see, even when calling a Javascript coroutine .. from C#, we still need to call it via StartCoroutine() - in the event we forget, it might be cool if an error is thrown rather than ignoring the function completely.
As I said, you need to use StartCoroutine in your C# code, but you're not doing that. You can leave out StartCoroutine in JS, but not C#.