x


destroy object after a delay?

How do i destroy object after a delay?

more ▼

asked Feb 01, 2012 at 07:04 AM

JBoy gravatar image

JBoy
212 95 93 96

Thanks All!

Feb 01, 2012 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, 2012 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, 2012 at 07:07 AM

BiG gravatar image

BiG
5.7k 13 22 69

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

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

more ▼

answered Feb 01, 2012 at 07:08 AM

MP2fps gravatar image

MP2fps
111 7 6 6

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, 2012 at 08:52 AM asafsitner
(comments are locked)
10|3000 characters needed characters left
more ▼

answered Feb 01, 2012 at 07:06 AM

fafase gravatar image

fafase
26.2k 66 73 137

(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, 2012 at 08:49 PM

Wiebren de Haan gravatar image

Wiebren de Haan
25 11 11 14

will you provide this in c#

Jul 30 at 03:26 PM Coffee with Venky
(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, 2013 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:

x1825
x1279
x298
x100
x65

asked: Feb 01, 2012 at 07:04 AM

Seen: 13218 times

Last Updated: Jul 30 at 03:26 PM