Hello
i need help to create a countdown timer in unity 4.6 using the new UI system.
Thanks
say the timer UI element is called “Timer”
private GameObject _timer;
private Text _timerText;
then in Start()
/Awake()
you get a reference to the Text
component on your “Timer” object.
_timer = GameObject.Find("Timer");
if (_timer == null)
{
Debug.Log("Timer not found!");
}
else
{
_timerText = _timer.GetComponent<Text>();
if (_timerText == null)
{
Debug.Log("Text component not found!");
}
}
then, in Update()
, you modify the text of the text component.
if (_timerText != null)
{
_timerText.text = timer.ToString("0");
}