Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - llamapixel

Pages: [1]
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.

  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class countDownTimer : MonoBehaviour {
  5.  
  6.         public UILabel NguiTimeLabel;
  7.         public float myTimer = 180.0f;
  8.         public int Triggerflag = 1;
  9.  
  10.         void Update () {       
  11.  
  12.  
  13.                 if(myTimer > 1.0) {
  14.                         myTimer -= Time.deltaTime;
  15.                         int minutes = Mathf.FloorToInt(myTimer / 60F);
  16.                         int seconds = Mathf.FloorToInt(myTimer - minutes * 60);
  17.                         string niceTime = string.Format("{0:0}:{1:00}", minutes, seconds);
  18.                         NguiTimeLabel.text= niceTime;
  19.                 }      
  20.                 if(myTimer < 1.0) {
  21.  
  22.                         if (Triggerflag == 1){
  23.                                 Debug.Log("Game Complete");
  24.                                 Triggerflag = 0;
  25.                                 NguiTimeLabel.text = "time's up";
  26.                         }
  27.  
  28.  
  29.                 }
  30.                
  31.         }
  32. }
  33.  

Pages: [1]