- Home /
Question by
ShockerXII · Dec 15, 2013 at 02:47 PM ·
colliderbullet
Destroy-able won't destroy
i have this script that when a bullet hits a destoryable tagged object it will destroy itself and the object it hits.
void OnCollisionEnter(Collider col)
{
if (col.gameObject.tag == "Destroyable")
{
Destroy(col.gameObject);
Destroy(this.gameObject);
}
}
the object im using to test is a sphere and has a rigidbody and sphere colider. the bullet is the same but smaller and with an "Ammo" tag.
Comment
Answer by Bunny83 · Dec 15, 2013 at 03:04 PM
OnCollisionEnter doesn't get a Collider as parameter but a Collision object. Only OnTriggerXXX functions just get the triggering collider.
A collision can have multiply contact points but at least 1
So you might want to change your code to:
void OnCollisionEnter(Collision col)
{
if (col.collider.gameObject.tag == "Destroyable")
{
Destroy(col.collider.gameObject);
Destroy(gameObject);
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613124221im_/https://answers.unity.com/themes/thub/images/avi.jpg)