as the title says two simple little scripts from youtube that the demnstrator got working and I triple checked that I have it EXACTLY the same yet they both are funky. Script #1 when it gets to the 30 second mark it ticks it off as being a minute. I got it to sort of work by changing the var minutes = time / 60; to var minutes = time / 120;. so after 60 seconds it ticks of a minute and all is good until the second minut comes around and the 1 minute remains at 1 minute. The second script won’t even tick of the first minute after 60 seconds. I have no idea what the deal is. Brand new scenes with nothing in them but the scripts
// this one turns 30 seconds into a minute
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class timer2 : MonoBehaviour {
public Text timerLabel;
public float startTimer = 0;
public float time;
void Update() {
if (startTimer > 0) {
time += Time.deltaTime;
var minutes = time / 60; //Divide the guiTime by sixty to get the minutes.
var seconds = time % 60;//Use the euclidean division for the seconds.
var fraction = (time * 100) % 100;
timerLabel.text = string.Format ("{0:00} : {1:00} : {2:00}", minutes, seconds, fraction);
} else {
//do nothing
}
}
}
///this one won't turn 60 seconds into a minute
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class newTimer : MonoBehaviour {
public Text timerText;
private float startTime;
private bool finnished = false;
void Start () {
startTime = Time.time;
}
// Update is called once per frame
void Update () {
if (finnished)
return;
float t = Time.time - startTime;
string minutes = ((int)t / 60).ToString ();
string seconds = (t % 60) . ToString ("f2");
timerText.text = minutes = ":" + seconds;
}
public void Finnish()
{
timerText.color = Color.red;
finnished = true;
}
}