Collision Problem (94920)

my coding has no errors but the bullet with a collider still will not destroy the tagged object. BTW that bullet has a box collider it is not floating. here is my code for incase `function OnCollisionEnter (other : Collider)
{
if(other.tag == “Bullet”)
{
Destroy(gameObject);
}
}

[21690-collision+problem.png|21690]`

1 Answer

1

OnCollisionEnter has parameter type of Collision not Collider

I changed it to collision and still it wont destroy the enemy object. function OnCollisionEnter (other : Collision) { if(other.tag == "Bullet") { Destroy(gameObject); } }

The tried and true way to debug this then is to add line debug.log("Collision event from " + other.name + " " + other.tag); i.e. verify your game is "hearing" the event you think it is and also verify you meet the proper definition of a "Collision"

function OnTriggerEnter (object : UnityEngine.Collider) { (object.tag == "Person"); Destroy(gameObject); } this worked but then my enemuies cant use physics with the y axis without them falling threw the grounds

i fixed my problem by playing around with it and i put the script on the enemy and made the bullet a trigger and this is what worked. function OnTriggerEnter (object : UnityEngine.Collider) { (object.tag == "Bullet"); Destroy(gameObject); }