- Home /
detonator question
I have made a bullet prefab and want it to trigger an explosion when it destorys a target. right now i have a couple of box targets with a detonator base prefab attached When hit with the bullet the destroy on impact works and they disapear. What i want to do is make an explosion as they disapear. do mi have to alter the bullet prefab script in some way?
function OnCollisionEnter(collision : Collision)
{ if (collision.gameObject.tag == "Finish") { Destroy(collision.gameObject); }
}
thanks for viewing
wayne
Answer by FLASHDENMARK · Dec 04, 2011 at 08:46 PM
You Instantiate a prefab:
var explosion : Transform; //Drag the explosion here.
function OnCollisionEnter(collision : Collision){
if (collision.gameObject.tag == "Finish"){
Instantiate(explosion, transform.position, transform.rotation);
Destroy(collision.gameObject);
}
}
I don't quiet get where you want the explosion to occur, if I am wrong please tell me.
thanks for the reply i just want the cubes to explode when hit and disapear
Answer by ByteSheep · Dec 04, 2011 at 09:49 PM
Explosions and fire etc are usually done using particle emitters. You should have an explosion prefab in your standard assets which should work fine. It should be under: Standard assets - Particles - Legacy Particles. If you are trying to instantiate an explosion as the bullet collides, then just add this after the "Destroy( );" part of your code:
Instantiate(Explosion, transform.position, transform.rotation);
You will then need to define the variable "Explosion" before the function OnCollisionEnter(). Your script should look something like this:
var Explosion : Transform;
function OnCollisionEnter(collision : Collision){
if (collision.gameObject.tag == "Finish")
{
Destroy(collision.gameObject);
Instantiate(Explosion, transform.position, transform.rotation);
}
}
In the Inspector window you have to assign the explosion prefab to the slot named "Explosion". Hope this helped..
Didn't see OrangeLightning had already answered, kind of repeated what he said..Oh well :)
Your answer
Follow this Question
Related Questions
Confused about enable 1 Answer
Move a detonator 1 Answer
Detonator -- Null reference error when adding component to empty game object 2 Answers
Detonator replacement for mobile? 0 Answers
Detonator Not Importing 0 Answers