- Home /
Question by
UFO_Pirate · Dec 26, 2013 at 01:48 AM ·
collisiondestroybullet
Destroy Bullet On Collision?
I can easily destroy a game object, but when I try to destroy a bullet(on an Automatic Gun) it destroys all of the bullets. So, how can I have it so that on collision it only destroys the one bullet that hits a wall?
Comment
Best Answer
Answer by aldonaletto · Dec 26, 2013 at 02:14 AM
You should post your script! Anyway, the problem is in the way you're destroying the bullet - maybe getting the bullet with GameObject.Find? Usually the bullet script does the job, like this:
function OnCollisionEnter(coll: Collision){
// do other jobs, then bullet destroys itself:
Destroy(gameObject);
}
If the OnCollisionEnter function is attached to the target (not the usual approach), destroy the colliding object instead:
function OnCollisionEnter(coll: Collision){
// do whatever you want to do, then destroy bullet:
Destroy(coll.gameObject);
}