Destroying object with timer

To People reading this,

I have been trying to get a script that will destroy an object after 3-5 seconds. It will count down from when the scene starts, not by anything else. Can someone please provide a script with instructions.

Thanks

How about some references instead of just an answer, this is all you need to get you started.

http://forum.unity3d.com/threads/69068-Simple-Timer?highlight=timer

var delay : float;
function Start(){
     Destroy(gameObject, delay);
}

@ Mitch

The script did not seem to work

so i changed it a bit and it still didnot work

var delay : float;
var wall : Transform;
function Start(){
Destroy(wall, delay);
}

What is wrong

Help,

Well, you cannot destroy the Transform component. Transform includes the following properties: position, rotation, and scale.

You should change your code to the following:

var delay : float;
[COLOR="red"]var wall : GameObject;[/COLOR]
function Start(){
Destroy(wall, delay);
}

@MightyMao

thanks

Actually you can destroy a Transform object :slight_smile: The rest of the object will persist; it will just no longer be in the hierarchy.