unity c# wait function code example
Example 1: how to make a line of code wait unity
//In the example below the script will right "Hello" and 3 seconds later write "Goodbye" in the console
Start()
{
//Call the function Example()
StartCoroutine(Example());
}
Example()
{
Debug.Log("Hello");
//wait 3 seconds
yield return new WaitForSeconds(3);
Debug.Log("Goodbye");
}
Example 2: wait time in unity
using System.Collections;
private void Start()
{
StartCoroutine(Wait());
}
IEnumerator Wait()
{
//To wait, type this:
//Stuff before waiting
yield return new WaitForSeconds(/*number of seconds*/);
//Stuff after waiting.
}