unity await for 1 second code example
Example 1: how to make a line of code wait unity
Start()
{
StartCoroutine(Example());
}
Example()
{
Debug.Log("Hello");
yield return new WaitForSeconds(3);
Debug.Log("Goodbye");
}
Example 2: wait time in unity
using System.Collections;
private void Start()
{
StartCoroutine(Wait());
}
IEnumerator Wait()
{
yield return new WaitForSeconds();
}
Example 3: unity3d coroutine to do for n seconds
StartCoroutine(GoLeft());
IEnumerator GoLeft() {
float timePassed = 0;
while (timePassed < 3){
timePassed += Time.deltaTime;
yield return null;
}
}