- Home /
Stop and Resume Timer
I have a problem with stop and resume timer. everytime i'm trying to stop the timer and then resume it again the timer has decreased too much time. Firstly > Timer Start @ 30.0 > @ 27.4 Timer Stop > Wait 1 or 2 seconds and then starts the timer again > The timer goes 25.2 not 27.4. does anyone know why or how?
this is my script.
private var enableTimer = false;
private var remains : float;
var timer : float = 30.0;
var txt : TextMesh;
var objects : GameObject[];
function Start(){
if(txt == null) GameObject.Find("Timer").GetComponent(TextMesh);
txt.text = "0";
remains = timer;
}
function Update () {
//timer -= Time.time;
if(enableTimer){
var clampedTime : float = Mathf.Clamp(Time.time,timer,0);
clampedTime -=Time.time;
if(txt) txt.text = clampedTime.ToString("f1");
}
}
function OnTriggerEnter(col : Collider){
if(col.gameObject.tag == "Player"){
enableTimer = true;
} else enableTimer = false;
}
Comment
Your answer
Follow this Question
Related Questions
How to reset Time.time ? 1 Answer
Coroutine Countdown Timer being extremely slow 1 Answer
Problem with countdown timer. 3 Answers
how to make a varied countdown timer 1 Answer