Hey, I've been searching around for a while now and can only find countdown timers when I want a timer that counts up when the scene is loaded... anyone know a answered question or example?
Here is my little counter script that will count up like a timer clock.
public Text timerText;
private float secondsCount;
private int minuteCount;
private int hourCount;
void Update(){
UpdateTimerUI();
}
//call this on update
public void UpdateTimerUI(){
//set timer UI
secondsCount += Time.deltaTime;
timerText.text = hourCount +"h:"+ minuteCount +"m:"+(int)secondsCount + "s";
if(secondsCount >= 60){
minuteCount++;
secondsCount = 0;
}else if(minuteCount >= 60){
hourCount++;
minuteCount = 0;
}
}
var Timer = 0.0;
function Update ()
{
Timer += Time.deltaTime; //Time.deltaTime will increase the value with 1 every second.
}
If you want to show it on a GUI then you can use this:
first create a guiText then place this script on it:
var Timer = 0.0;
function Update ()
{
Timer += Time.deltaTime;
guiText.text = "" + Timer;
}
You can take a look at this.
var timer:var=0;
function Update(){
timer+=Time.deltaTime;
}
var Timer : float;
function Update ()
{
Timer += Time.deltaTime;
guiText.text = Timer.ToString();
}
Put this in an GUI Text
var textTime : String;
function Start () {
}
function Update () {
var Crono = Time.time;
var minutos : int = Crono / 60;
var segundos: int = Crono % 60;
var milesimas: int = (Crono * 100)% 100;
textTime = String.Format ("{0:00}:{1:00}:{2:00}", minutos, segundos, milesimas);
GetComponent(GUIText).text = textTime.ToString();
}
void TimeUpdate()
{
TotalSeconds += Time.deltaTime;
minuteCount = TotalSeconds / 60;
secondsCount = TotalSeconds % 60;
timerText.text = minuteCount + ām:ā + (int)secondsCount + āsā;
if (secondsCount >= 60)
{
minuteCount++;
secondsCount %= 60;
}
}