Destroy Object After Time

I am trying to make it so that when you are near an object, score goes up, but the object that you are near gets destroyed after a certain amount of time. Right now, I’m using the following code, but the object is never destroyed, even as time passes 0:

var Mood : Transform; 
var Thought : Transform; 
var  score : Score;
var time = 1000;

var distanceLimit : float = 5.0; 

function Update() { 
if (Vector3.Distance(Mood.position, Thought.position) < distanceLimit) {
score.AddToScore   () ;
--time;
}
else{
}
		if (time = 0)  {
		
		Destroy (gameObject) ;
}

Did I do something wrong?
Also, any suggestions are appreciated.
Thanks

Hello,
Try,

 Destroy(gameObject, 5)

5 is the time in seconds

Ray

^He’s got the easy solution.

Also, “if (time = 0)” is meaningless - actually i’m surprised it doesn’t give you a compile error. You want time == 0, or better yet, time <= 0.

the reason being that - at least this is how it worked in C++ - “if (time = 0)” means, “assign the value of 0 to time, and then return that value”; so that would be equivalent to “if (0)”, or “if (false)”.

And for god’s sake fix your indentation :stuck_out_tongue: