x


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;
}
more ▼

asked Feb 18, 2012 at 07:21 AM

COLLAnitySV gravatar image

COLLAnitySV
36 67 46 48

(comments are locked)
10|3000 characters needed characters left

0 answers: sort voted first
Be the first one to answer this question
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x839
x534
x133
x99
x43

asked: Feb 18, 2012 at 07:21 AM

Seen: 1172 times

Last Updated: Feb 18, 2012 at 07:21 AM