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...
So what I need is a way to make all three update - or my mistake pointed out...
- using UnityEngine;
- using System.Collections;
- using System;
- public class EHBoardTimer : MonoBehaviour {
- public UILabel theMilliSeccondsCounter;
- public UILabel theSeccondsCounter;
- public UILabel theMinutesCounter;
- public float levelTime = 150.0f;
- private float startTime = 0.0f;
- private float theDeltaTime = 0.0f;
- private float theMinutes = 0.0f;
- private float theSecconds = 0.0f;
- private float theMillisecconds = 0.0f;
- // Use this for initialization
- void Start ()
- {
- startTime = Time.time;
- }
- // Update is called once per frame
- void Update ()
- {
- theDeltaTime = Time.time - startTime;
- theDeltaTime = levelTime - theDeltaTime;
- // get milliseconds to two dp by removing truncated value
- //theDeltaTime = (float)Math.Round((double)theDeltaTime, 2);
- //theMillisecconds = theDeltaTime - Mathf.Round(theDeltaTime);
- theDeltaTime = Mathf.Round(theDeltaTime);
- // get secconds
- theSecconds = theDeltaTime %60;
- Debug.Log(theSecconds);
- // get minutes
- theMinutes = theDeltaTime / 60;
- theMinutes = Mathf.Round(theMinutes);
- // write to screen
- theMilliSeccondsCounter.text = theMillisecconds.ToString();
- theMinutesCounter.text = theSecconds.ToString();
- theMinutesCounter.text = theMinutes.ToString();
- }
- }