x


Timer-function which calculates how long an enabled script is running yet?

Hi,

i have to script an animation. At a specific point of the game i want to enable an addition script where i need to know, how long that just enabled script is running. The "Timer.time" returns only the time how long the complete scene is running yet. Is there way to get that information? I simple need a "startTimer"-function..

Thanks

more ▼

asked Jan 15 '10 at 01:57 PM

yosh gravatar image

yosh
901 73 81 94

Spelling nazi: please update your title from "caluculates" to "calculates".

Jan 16 '10 at 08:44 AM Ricardo
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

You need to store Time.time in a variable on that script, when the script is enabled. Something like this:

var timeEnabled : float = 0;

function OnEnable ()
{
    timeEnabled = Time.time;
}

function GetRunningTime()
{
    return Time.time - timeEnabled;
}

You can then call: yourScript.GetRunningTime() to find out how long it has been enabled.

more ▼

answered Jan 15 '10 at 02:04 PM

duck gravatar image

duck ♦♦
41.4k 95 152 415

Oh yeah!!! Great to know. Thanks a lot.

Jan 15 '10 at 02:14 PM yosh
(comments are locked)
10|3000 characters needed characters left
Your answer
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:

x5270
x588
x356

asked: Jan 15 '10 at 01:57 PM

Seen: 2000 times

Last Updated: Jan 19 '10 at 04:30 PM