I am currently trying to understand IEnumerator and Coroutine in the context of Unity and am not too sure that it is performing a "yield return null". At the moment, I believe that it basically pauses and waits for the next frame, and in the next frame it will return to execute the while statement again.
If I omit the "yield return null", it seems that the object will instantly move to the destination, or perhaps "skip a lot of frames." So, I think, my question is how is this "yield return null" function inside this while loop and why is it needed.
void Start () {
StartCoroutine(Move());
}
IEnumerator Move(){
while (a > 0.5f){
... (moves object up/down)
yield return null;
}
yield return new WaitForSeconds(0.5f);
.... (moves object up/down)
StartCoroutine(Move());
}
source
share