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