C# actually has a library of features much like Pythong’s IterTools called Linq. With Linq, you can turn any IEnumerable (Type that on the blackboard 40 times, please) into a query to just about anything imaginable.
I’m a .net developer and IEnumerable/ IEnumerator in .NET is just to make some class a collection so you can iterate through it using foreach for example. The functionality taught here is Unity’s way of utilizing the IEnumerator for it’s custom usage, it’s actually pretty awesome though.
It is, really. When Unity was inifially under development, the Mono C# stack it was running on had no real provision for coroutines or threading. At the time, Unity wanted to keep the whole game on the main thread anyways, and they came up with a pretty clever use of IEnumerators that I don’t think the folks at Microsoft envisioned to make Coroutines a thing.
As for me, coroutine will be useful when you want to make action in stackable way. For example if we want to spawn objects in order.
For me, before Unity, IEnumerators was an iterator interface that allows you to iterate through a list of items. After learning about Unity, I learn coroutines, and the common use I see is as an async timer to do things after waiting the time.
I used coroutines for a countdown at the beginning of my game. With “yield return null” it basically behaves like update, but will not be executed after the termination criteria (e.g. Time.time > countdown) has been met.
IEnumerators coroutines make handy replacements for Update loops! I have a game I wrote a couple of years ago that didn’t use Update() at all. As a turn based game, it worked better to only have a given controller or component Update() when it was that character’s turn.
I believe IEnumerators are good for when we would like to move through a collection of items as well as when we would like to execute code over a set period of time. For example, I could see a scenario in a platformer game where the platforms the player is walking on disappear over time. The player must complete the level before time runs out and all the platforms are gone. In this example, an IEnumerator would be used to cycle through the platforms, destroying them, yielding for a period of time, and then moving on to the next platform as time went on.
Nearly fell asleep during this video.