- Home /
Question by
oinkoinkflapflap · Mar 15, 2011 at 08:51 PM ·
javascripttimeenabledlife
turning script on after time
i've created this script:
var lifeTime = 1.0;
function Awake ()
{
if (lifeTime <=0)
{
GetComponent("AI script Looking").enabled = true;
}
}
there are no errors but it doesn't work at all, i want it to turn on after time... thanks all :D
Comment
Answer by DaveA · Mar 15, 2011 at 09:08 PM
Where does lifeTime change? It's never negative. Try this (there are many ways to do this):
var delay = 1.0; var startTime = 0.0;
function Awake() { startTime = Time.time; }
function Update () { if ((Time.time - startTime) >= delay) { GetComponent("AI script Looking").enabled = true; } }
thanks bit, if i want it to start after say 20 secs, which do i change?? thanks :)
Your answer
![](https://koobas.hobune.stream/wayback/20220613113034im_/https://answers.unity.com/themes/thub/images/avi.jpg)