- Home /
How to compare the game time to a float?
Im trying to make a short script where when you start the object is de-activated, and if the time is = 2 seconds, it will set the gameObject to active, but I can't figure out how. (I'm 100% noobish to unity so this is probably a dumb question.)
function Start()
{
gameObject.SetActive(false);
}
function Update () {
if (Time.time = 2)
{
gameObject.SetActive(true);
}
}
Answer by PlasmaByte · Dec 28, 2013 at 11:36 PM
Firstly I'm pretty sure you need two = signs when doing a comparison, single = is assignment, not entirely certain about javascript so correct me if I'm wrong.
The reason it's probably not working is because Time.time is a float, decimal, so very unlikely to even be exactly 2. Use an inequality instead e.g. Time.time > 2
Another thing to note, this needs to be called from a script which is not attached to the object otherwise this script will be disabled and so unable to perform its check or reactivate the object!
I appreciate the comment, and I used all of your advice but the game object is still de-activated. I changed it to an inequality as well, but something is still not right. Anyway, thanks for the response!
Your answer
Follow this Question
Related Questions
Digital Clock: Time.time > 60 2 Answers
Parenting after X time with collision, I dont get it! 1 Answer
Noob needs help : "expecting }, found " " 2 Answers
Random time activate/deactivate object 1 Answer
Gradually scale platform? 4 Answers