x


destroy object after a delay?

How do i destroy object after a delay?

more ▼

asked Feb 01 '12 at 07:04 AM

JBoy gravatar image

JBoy
152 34 45 48

Thanks All!

Feb 01 '12 at 11:13 PM JBoy

@JBoy: don't post comments as answers. Answers should exclusively be used to answer the question. Read the FAQs for more information.

I've converted your answer into a comment.

Feb 01 '12 at 11:16 PM Bunny83
(comments are locked)
10|3000 characters needed characters left

5 answers: sort voted first

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.

more ▼

answered Feb 01 '12 at 07:07 AM

BiG gravatar image

BiG
5.5k 4 15 55

(comments are locked)
10|3000 characters needed characters left

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

more ▼

answered Feb 01 '12 at 07:08 AM

MP2fps gravatar image

MP2fps
81 2 2 3

This.

The Destroy(); method has the functionality you are looking for integrated already. Just use the above overload and you're good to go.

Feb 01 '12 at 08:52 AM asafsitner
(comments are locked)
10|3000 characters needed characters left
more ▼

answered Feb 01 '12 at 07:06 AM

fafase gravatar image

fafase
19.7k 18 27 68

(comments are locked)
10|3000 characters needed characters left
var Seconds = 10;

function Update(){
    Destroy();
}

function Destroy(){
    yield WaitForSeconds(Seconds);
    Destroy(gameObject);
}

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

more ▼

answered Nov 22 '12 at 08:49 PM

Wiebren de Haan gravatar image

Wiebren de Haan
1 4 5 5

(comments are locked)
10|3000 characters needed characters left

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);
more ▼

answered Dec 05 '13 at 07:05 PM

wrobel221 gravatar image

wrobel221
16 1

(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x1554
x1079
x247
x87
x56

asked: Feb 01 '12 at 07:04 AM

Seen: 6834 times

Last Updated: Dec 05 '13 at 07:05 PM