unity what is a coroutine code example
Example 1: unity coroutine
void Start() {
StartCoroutine("func"); // Start coroutine named "func"
}
IEnumerator func() {
Debug.Log("Hello");
yield return new WaitForSecondsRealtime(1); //Wait 1 second
Debug.Log("World");
}
Example 2: how to start a coroutine in c#
void Start()
{
StartCoroutine(Test());
}
IEnumerator Test()
{
yield return new WaitForSeconds[2];
}