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.
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.