x


destroy object after a delay?

How do i destroy object after a delay?

more ▼

asked Feb 01, 2012 at 07:04 AM

avatar image

JBoy
212 96 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

avatar 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

avatar image

MP2fps
126 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

I should have realized this through the Scripting API. I'd thumbs up but can't yet. Thanks.

Jan 14 at 12:25 PM Guppie1337
(comments are locked)
10|3000 characters needed characters left
more ▼

answered Feb 01, 2012 at 07:06 AM

avatar image

fafase
27.9k 66 83 141

(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

avatar image

wrobel221
31 2

(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

avatar image

Wiebren de Haan
25 11 11 14

will you provide this in c#

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

x1903
x1321
x315
x105
x68

asked: Feb 01, 2012 at 07:04 AM

Seen: 15247 times

Last Updated: Jan 14 at 12:25 PM