- Home /
Countdown To Start Game
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?
Answer by gbelini · Jan 02, 2013 at 01:37 PM
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;
}
}
}
}
Thanks, but I already figured it out, and I prefer to work in Java :D
Answer by Orloffyeah · Dec 27, 2012 at 10:17 PM
Thanks, but could you explain me how the IEnumerator function works?
Your answer
![](https://koobas.hobune.stream/wayback/20220613085954im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Help with BCE0019: 'enabled' is not a member of 'UnityEngine.Component' 1 Answer
Problem with countdown timer. 3 Answers
choose a car and customize a car(Main Menu} 1 Answer
Arcade car phisics 1 Answer
Script variables resetting on play 0 Answers