- Home /
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.....
What's the question? Does this code not work? If not, what does it do? What did you expect it to do?
the question is how do i start a explosion when the rocket is destroyed ins$$anonymous$$d of it just disappear.
@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
Answer by qJake · May 20, 2010 at 09:30 PM
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);
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
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.
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..
So just do what you already did for the rocket, except do it for the explosion (using Invoke).
Your answer
Follow this Question
Related Questions
How to get rid of (cloned) particles after an explosion 2 Answers
i want to add fire shot at enemy gun explosion 1 Answer
Delete Explosion After 1 Second Script Not Working 2 Answers
problem with shooting killing script 1 Answer
How could i make it so that my bullets destroy after x amount of seconds? 2 Answers