There are differences in the syntax of C# and JavaScript as follows:
JavaScript:
yield WaitForSeconds(3); //pauses for 3 seconds yield WaitForMyFunction(); //start coroutine function WaitForMyFunction() {...} //coroutine function
C#:
yield return new WaitForSeconds(3); //pauses for 3 seconds yield return WaitForMyFunction(); //start coroutine IEnumerator WaitForMyFunction() {...} //coroutine function
However, if we want to wait for the user input in C#, which might be over several frames, we will have to use StartCoroutine
. In JavaScript, the compilers will automatically do it for us.
JavaScript:
yield WaitForMyFunction(5); //This is similar with yield StartCoroutine(WaitForMyFunction(5)); function WaitForMyFunction(waitTime : float) {...} //coroutine function
//Need to put StartCoroutine yield return StartCoroutine(WaitForMyFunction(5)); IEnumerator WaitForMyFunction(waitTime : float) {...} //coroutine function
3.145.96.86