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.


Topics - greigy

Pages: [1]
1
NGUI 3 Support / Controlling NGUI lables from one script.
« on: February 19, 2015, 01:32:19 AM »
The following is a script that I am in the process of creating for the purposes of a count down timer. For the sake of alignment and effects, I have created three labels as individual parts, but am seemingly unable to update the seconds. By disabling (commenting out) the minutes, the seconds are updated. - I have got rid of the milsec calcs to make sure they aren't influencing anything.

So what I need is a way to make all three update - or my mistake pointed out...


  1. using UnityEngine;
  2. using System.Collections;
  3. using System;
  4.  
  5. public class EHBoardTimer : MonoBehaviour {
  6.  
  7.         public UILabel theMilliSeccondsCounter;
  8.         public UILabel theSeccondsCounter;
  9.         public UILabel theMinutesCounter;
  10.         public float levelTime = 150.0f;
  11.  
  12.         private float startTime = 0.0f;
  13.         private float theDeltaTime = 0.0f;
  14.  
  15.         private float theMinutes = 0.0f;
  16.         private float theSecconds = 0.0f;
  17.         private float theMillisecconds = 0.0f;
  18.  
  19.         // Use this for initialization
  20.         void Start ()
  21.         {
  22.                 startTime = Time.time;
  23.        
  24.         }
  25.        
  26.         // Update is called once per frame
  27.         void Update ()
  28.         {
  29.                 theDeltaTime = Time.time - startTime;
  30.                 theDeltaTime = levelTime - theDeltaTime;
  31.  
  32.                 // get milliseconds to two dp by removing truncated value
  33.                 //theDeltaTime = (float)Math.Round((double)theDeltaTime, 2);
  34.                 //theMillisecconds = theDeltaTime - Mathf.Round(theDeltaTime);
  35.                 theDeltaTime = Mathf.Round(theDeltaTime);
  36.  
  37.                 // get secconds
  38.                 theSecconds = theDeltaTime %60;
  39.                 Debug.Log(theSecconds);
  40.  
  41.                 // get minutes
  42.                 theMinutes = theDeltaTime / 60;
  43.                 theMinutes = Mathf.Round(theMinutes);
  44.  
  45.                 // write to screen
  46.                 theMilliSeccondsCounter.text = theMillisecconds.ToString();
  47.                 theMinutesCounter.text = theSecconds.ToString();
  48.                 theMinutesCounter.text = theMinutes.ToString();
  49.         }
  50. }
  51.  

Pages: [1]