- Home /
Bullets Not Deleted Upon Collision
Hello, I'm new to Unity, but not to coding. I recently tried making a script that will delete bullets upon collision, but it doesn't work.
function OnCollisionEnter(collision : Collision)
{
if(collision.gameObject.tag == "Ammo")
{
Destroy(collision.gameObject);
}
}
any help would be appreciated.
Answer by Statement · Mar 10, 2013 at 03:53 AM
Attach the debugger and step through the code to find the issue.
Is the OnCollisionEnter callback being called? Does the if-statement evaluate to true? If not, why so?
Destroy surely works, but perhaps your bullet game object has a child object with the collider. In that case you'd destroy the game object with the collider but not the parent game object, but I doubt you've set it up like this.
$$anonymous$$oreover @Swordslam46, have you remembered to tag the object "Ammo"? Happens a lot believe me ...
Yes, the tag is not the name nor the layer of the object.
Your answer
Follow this Question
Related Questions
Collision.point not working 1 Answer
Realistic Hands and Physics implementation? 1 Answer
Code isn't Recursive in update? 2 Answers
Object's pass through each other? 2 Answers
Anti-Gravity vehicle bounce-back? 1 Answer