help with movement code

Well IEnumerators are of COURSE useful. They’re a key language feature.

Coroutines can be useful, but I argue against their uses most of the time.

Here is my criteria for a coroutine:

  • the code truly affects nothing else in a material way

  • the code is tolerant of null references if it drives something external

  • you never intend to stop it by any means except Destroy()-ing the underlying GameObject

And while we’re at it, to dispel some of the silly beliefs about Update vs Coroutines:

Hint: Update and Coroutines run in the same thread, one after the other, never at the same time.


Coroutines in a nutshell:

Splitting up larger tasks in coroutines:

Coroutines are NOT always an appropriate solution: know when to use them!

“Why not simply stop having so many coroutines ffs.” - orionsyndrome on Unity3D forums

Our very own Bunny83 has also provided a Coroutine Crash Course:

1 Like