1
NGUI 3 Support / Re: A simple Count down timer ? [SOLVED]
« on: May 31, 2014, 08:19:23 PM »
Hi guys,
Thanks for posting this.
I managed to get a simple timer to work with this advice.
Thanks for posting this.
I managed to get a simple timer to work with this advice.
- using UnityEngine;
- using System.Collections;
- public class countDownTimer : MonoBehaviour {
- public UILabel NguiTimeLabel;
- public float myTimer = 180.0f;
- public int Triggerflag = 1;
- void Update () {
- if(myTimer > 1.0) {
- myTimer -= Time.deltaTime;
- int minutes = Mathf.FloorToInt(myTimer / 60F);
- int seconds = Mathf.FloorToInt(myTimer - minutes * 60);
- string niceTime = string.Format("{0:0}:{1:00}", minutes, seconds);
- NguiTimeLabel.text= niceTime;
- }
- if(myTimer < 1.0) {
- if (Triggerflag == 1){
- Debug.Log("Game Complete");
- Triggerflag = 0;
- NguiTimeLabel.text = "time's up";
- }
- }
- }
- }