Can someone explain what IEnumerators and for statements are?
Sorry for such an awful question, but I have checked the Scripting API and did a good amount of googling. But basically I still don't understand the purpose of it. I need a basic understanding of how it works, and how and when to use it. Maybe an example of a for statement and an IEnumerator method? I also don't really understand loops. Sorry for asking of so much, but if anyone is willing to explain anything it would be greatly appreciated!
You might find the "Learn" section helpful too:
Among other useful things, it has a scripting section, which also contains tutorials for "6. Loops", and "27. Enumerations":
Answer by hexagonius · Sep 13, 2015 at 08:24 AM
a for loop is primarily used for iterating arrays, lists, stacks, queues... everything basically that contains more than one value.
one example is the returned array of a Physics.RaycastAll. if you want to check for some condition on all items in the array run a for loop.
An indepth understanding of IEnumerator is not needed for using them in Unity and if you must know check out MSDN for C#.
They are primarily used for scripting time events like cutscenes. every method with that return type is capable of yielding. it means you can start them with StartCoroutine and do stuff like "wait 5 seconds", "wait for another coroutine to finish"... this can all be written down like a script for a movie without worrying about counting time or something.