Skipping over timer

Hello, I have a system where when the game starts a gui will say “foo” and after 5 seconds it change’s to “bar”, but its just going to bar without waiting 5 seconds.

Code

void Update () {
	text1.text = "foo";
	wait (5);
	text1.text = "bar";
}

IEnumerator wait(int time)
{
	yield return new WaitForSeconds(time);
}

That’s not quite how Coroutines work, and you can’t do waiting directly inside Update.

Try this:

void Start()
{
    StartCoroutine(FooBar(5));
}

IEnumerator FooBar(float time)
{
  text1.text = "foo";
  yield return new WaitForSeconds(time);
  text1.text = "bar";
}

I moved the StartCoroutine call to Start because you don’t want to call that every frame or you’ll be starting a new coroutine each frame. If you need to start it in Update then you’ll want some condition in place so it only starts it when needed.