Hi, I have been looking around in the forums for a timer script that will allow me to add a simple display showing the time left to start a race and in the mean time your car is deactivated, but I haven’t been able to implement it into the game.
How could I make such a timer display in a GUIText?
Thanks, but could you explain me how the IEnumerator function works?
Hi, you could try this
using UnityEngine;
using System.Collections;
public class Timer : MonoBehaviour {
private float _totalTime = 5.0f;
private float _currentTime = 0;
// Use this for initialization
void Start () {
}
// Update is called once per frame
void Update ()
{
DegreaseTime();
}
void OnGUI()
{
GUI.Label(new Rect(Screen.width / 2, Screen.height /2, 150, 100), "" + _totalTime);
}
private void DegreaseTime()
{
float delta = Time.deltaTime;
_currentTime += delta;
if (_currentTime >= 1 )
{
if (_totalTime - 1 <= 0)
{
_totalTime = 0;
//Start Game
}
else
{
_totalTime -= 1;
_currentTime = 0;
}
}
}
}