destroy object after a delay?

How do i destroy object after a delay?

var destroyTime = 5;
function Update () {
Destroy(gameObject, destroyTime);

You can just set time delay in Destroy method

Object.Destroy(gameObject, 2.0f);

Here’s the method description

static void Destroy(Object obj, float t = 0.0F);

It’s easy:

Define a function like this:

var delay = 2.0; //This implies a delay of 2 seconds.

function WaitAndDestroy(){
   yield WaitForSeconds(delay);
   Destroy (gameObject);

Call this function when you want to destroy it.

All is there

Hope that helps

var Seconds = 10;

function Update(){

function Destroy(){
	yield WaitForSeconds(Seconds);

Add this to a javascript, set the time in Seconds (Use the var). And the gameobject will be destroyed after in this script 10 seconds