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
87 19 30 34

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

4 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
4.7k 4 13 49

(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
66 2 2 2

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
10.4k 9 15 40

(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
-14 3 3 4

(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:

x1089
x764
x179
x58
x37

asked: Feb 01 '12 at 07:04 AM

Seen: 1939 times

Last Updated: Nov 22 '12 at 08:49 PM