Enemy death help

I am new to scripting so here is my question. I know there must be some way to delete an enemy after two rigidbodys with tags hit a object but I can not figure this out. here is my code. All I need is that part. I have tried many different things but none of them will work. can someone show me a good tutorial or give an idea. thank you. (codes a js) Thank you everyone.

function OnCollisionEnter(theCollision : Collision){
   if(theCollision.gameObject.tag=="Bullet") {
     Destroy(gameObject);
   }
}

I don’t have a tutorial, but I can explain what’s happening (as I imagine it).

When the physic engine simulate the movements since the last time, it’s going to looks if there was any collision event. That means the objects we’re talking about need a collider and something that makes them move during the physic loop, usually a rigidbody. Note that changing the transform.position of a rigidody won’t raise an event, it need to be an AddForce (It could with kinematics, but let’s keep it simple).

When an event occures, Unity send message to both objects. If at least one of them is a trigger, those message are of the form OnTriggerXXX, if not OnCollisionXXX.

I suppose you want your characters to die when they are touched by a bullet. If this script is attached to the character’s gameobject, which have a collider (isTrigger false), if the bullet have a collider(isTrigger false), a rigidbody not kinematic and if you used AddForce to launch it, if both objects are on a layer that can collide between each other (Physic Manager), then it should work.


Also, this is my 1000th answer, here is my proudest realisation, to celebrate \o/