- Home /
Calling IEnumerator function with variables does not do anything
I'm trying to convert the HSController.js script from the wiki to C# and I'm having a bit of a problem. I have simplified the problem to this:
public void Start () { test("Jack"); }
public IEnumerator test(string MyName) { yield return new WaitForSeconds(1); Debug.LogWarning("My name is " + MyName);
}
What happens is that I don't get a log warning. When I remove the "MyName" property from the function, and just call "test();" it works.
Can anyone explain to me why? And how to solve this issue?
As I said, I'm trying to convert HSController.js to C#, which uses yield to wait for a high-score to be submitted to a PHP script. The function needs parameters as well (name, score, etc...). The JS script works fine, but in JS I don't have to work with IEnumerator.
Thanks in advance.
Answer by Mike 3 · Jan 10, 2011 at 05:50 PM
You have to use StartCoroutine(test()); to call the function
Unity does some work behind the scenes to keep calling MoveNext() on the enumerator, all of which is a little more transparent with javascript
Your answer
Follow this Question
Related Questions
Yield Wait for Seconds (A little help here) 2 Answers
WaitForSeconds is breaking out of my IEnumerator 1 Answer
Why Won't My Coroutine Yield? 2 Answers
Coroutine error with result 1 Answer
Waiting twice inside coroutine (C#) 2 Answers