- Home /
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
Spelling nazi: please update your title from "caluculates" to "calculates".
Answer by duck · Jan 15, 2010 at 02:04 PM
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.
Your answer
Follow this Question
Related Questions
pause timer or player using Time.timeScale 1 Answer
The name 'Joystick' does not denote a valid type ('not found') 2 Answers
How do you save timer with PlayerPrefs? 1 Answer
Unity3D Timer. 1 Answer
How to work a real life timer? 2 Answers