Make label disappear after 1 second?

Hi, so I’m making a car game for my university project and I’m trying to implement a countdown timer at the begging of the game which will countdown from 3 and tell the player to go.

I have it working as it should, the player and AI can’t move until the timer reaches 0 but the problem is that I’m using labels to display “3”, “2”, “1” and “GO!” when it should be displayed but the labels don’t disappear and just stack. I’ve tried a coroutine and using a boolean but neither worked. Here’s the code from the OnGUI method:

using UnityEngine;
using System.Collections;

public class StartCountdownScript : MonoBehaviour 
{

	public float countdownTime = 7.0f;
	public float resetPlayerTorque;
	public float resetAITorque;

	public GameObject[] aiCars;
	public GameObject player;

	public GUIStyle customGUIStyle;

	public int labelWidth = 250;
	public int labelHeight = 250;

	public bool toggleLabel = false;


	void OnGUI()
	{
		if (countdownTime <= 5)
		{
		 	GUI.Label(new Rect(Screen.width/2 - labelWidth/2, Screen.height/2 - labelHeight/2, labelWidth, labelHeight), "3", customGUIStyle);
		}

		if (countdownTime <= 3)
		{
			GUI.Label(new Rect(Screen.width/2 - labelWidth/2, Screen.height/2 - labelHeight/2, labelWidth, labelHeight), "2", customGUIStyle);
		}

		if (countdownTime <= 1)
		{
			GUI.Label(new Rect(Screen.width/2 - labelWidth/2, Screen.height/2 - labelHeight/2, labelWidth, labelHeight), "1", customGUIStyle);	
		}

		if (countdownTime <= 0)
		{
			GUI.Label(new Rect(Screen.width/2 - labelWidth/2, Screen.height/2 - labelHeight/2, labelWidth, labelHeight), "GO!", customGUIStyle);
		}
	}

Can someone tell me how to go about displaying each label for just 1 second then disappearing? I’m sure I’m overlooking something so simple or have made a silly mistake.

All help is appreciated, Thanks :wink:

They’re stacking because 0<=1<=3<=5… they’re all less than the first one. You could use a bunch of if/else-if’s to do it, but let’s do a switch().

Ex :

	float time = 7f ;
	string content = "" ;
	bool countDownDone = false ;

	void Update()
	{
        //decrement time
	    time -= Time.deltaTime ;
	}


	void OnGUI()
	{
	    CountDown() ;
	}

	void CountDown()
	{
        //early-out of this function if we've already done the countdown
	    if(countDownDone) return ;

		int t = Mathf.FloorToInt(time) ;
		switch(t)
		{
			case 4 :
				content = "3" ;
				break ;
			case 3 :
				content = "2" ;
				break ;
			case 2 :
				content = "1" ;
				break ;
			case 1 :
				content = "GO!!" ;
				break ;
			case 0 :
				countDownDone = true ;
				break ;
		}

		GUI.Label(--yourRect--, content, --yourStyle) ;
	}

Where do you decrease your countdownTime variable? I suggest adding a line to the update function as below;

countdownTime -= Time.deltaTime;

also don’t make seperate if statements and use else if.