x


Trigger explosion on rocket

Hi

i need help with how do i trigger an explosion for my rockets when the time is up instead of them just being destroyed.

This is the code im using

var timeOut = 2.7;

var detachChildren = false;

function Awake ()

{    
         Invoke ("DestroyNow", timeOut);

}


function DestroyNow ()
{    

    if (detachChildren) {
               transform.DetachChildren ();
    }    
    DestroyObject (gameObject);

}

I have downloaded the Detonator Package wich im trying to use for this...

Thanks for your help.....

more ▼

asked May 20 '10 at 10:04 AM

Marcus gravatar image

Marcus
41 6 6 11

What's the question? Does this code not work? If not, what does it do? What did you expect it to do?

May 20 '10 at 11:34 AM Lucas Meijer 1 ♦♦

the question is how do i start a explosion when the rocket is destroyed instead of it just disappear.

May 20 '10 at 07:39 PM Marcus

@Lucas He wanted to know how to use the Detonator pack to instantiate an instance of one of the explosion prefabs that's included with the pack, though I agree, the question was pretty vague... took me awhile to decipher it. :P

May 20 '10 at 09:32 PM qJake

sorry about that

May 20 '10 at 10:00 PM Marcus
(comments are locked)
10|3000 characters needed characters left

1 answer: sort voted first

Just add a reference to a Detonator prefab (from the pack), fill it in using the Inspector, and then instantiate it. It should go off right away if you didn't mess with anything in the Detonator settings.

// Fill this in using the Inspector
var explosion : GameObject;

Then, before you destroy the object, do something like this:

Instantiate(explosion, transform.position, Quaternion.identity);
more ▼

answered May 20 '10 at 09:30 PM

qJake gravatar image

qJake
11.6k 43 78 161

But what if you want the actual rockets (that im firing) to explode after the timeline that ive set to 2.7 seconds as you can see in the code. Right know when i tried your code the explosion takes place 2.7 seconds in to the game without me even having to fire the rockets

May 20 '10 at 10:57 PM Marcus

You have to put the explosion on the rocket object, so when the rocket is fired and explodes, the explosion gets spawned. This code won't work if it's not "on" the rocket.

May 21 '10 at 12:13 AM qJake

Ok now it works that when i press the shoot button the explosion and the firing of the rockets happens simultaneously, but i want that the explosion to occur at the end of the rockets "life cycle" when the rockets are destroyed. Sorry if i was unclear about what i needed..

May 21 '10 at 12:59 AM Marcus

So just do what you already did for the rocket, except do it for the explosion (using Invoke).

May 21 '10 at 04:36 AM qJake

Thank you i works now

May 21 '10 at 05:07 PM Marcus
(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:

x764
x275
x161

asked: May 20 '10 at 10:04 AM

Seen: 1657 times

Last Updated: May 20 '10 at 09:27 PM