I try but it seem like I can’t really understand the concept at all.
Can you explain it in the easy way please?
I try but it seem like I can’t really understand the concept at all.
Can you explain it in the easy way please?
A coroutine is a method that you can execute through several frames opposite to a regular method which must execute completely within 1 frame.
If you want to start a coroutine you create the method as an IEnumerator and you can’t just call it like a regular function, it needs to be started with StartCoroutine(FunctionName(parameters));
example:
void Start() {
StartCoroutine(Wait(3f));
}
IEnumerator Wait(float sec) {
yield return new WaitForSeconds(sec);
print("complete");
}
This would wait 3 seconds then print “complete”.
Only a monobehaviour can start a coroutine, and it must contain a yield statement.
Check the unity manual though it gives you a much better explanation than i do. Unity - Manual: Coroutines