xxxxxxxxxx
void start() => StartCoroutine(MyIEnumerator());
IEnumerator MyIEnumerator()
{
Debug.Log("Hello world!");
yield return new WaitForSeconds(3);
Debug.Log("Goodbye world!");
}
xxxxxxxxxx
// This is a new function.
IEnumerator WaitForSeconds(float time){
shouldWalk = false;
yield return new WaitForSeconds(time);
shouldWalk = true;
}
Start(){
Debug.Log("Hi");
WaitForSeconds(10);
Debug.Log("Bye.");
//Here, We are printing Hi to the console, wait 10 seconds, and then print bye to the console.
}
xxxxxxxxxx
void start()
{
Invoke("DoSomething", 2);//this will happen after 2 seconds
}
void DoSomething()
{
Debug.Log("2 seconds has passed!");
}