Checking for a name on collision (solved!)

I’ve been through the script reference for Collision and some other questions on unityAnswers, and they all lead me to believe that my code should work, but evidently I’ve done something wrong. Take a look.

void OnCollisionEnter(Collision collide)
{	
	if(collide.gameObject.name == "Hitbox")		
	{
		Destroy(gameObject);
		
	}		
}

I know that the collision is being recognized, because if I remove the if statement, the object is destroyed just fine, and if I leave it in, the two rigidbodies still interact physically. They’re both RigidBody/Colliders, so that shouldn’t be a problem anyway. Additionally, I’ve tried a few permutations of “collide.collider.(etc)” to no avail. Hitbox is a prefab I’ve constructed.

I’m kind of embarrassed that I’m having so much trouble with this, but clearly I’m missing something here. Thanks a lot for any help you can provide.

Edit:

I was able to create a workaround by assigning a tag to the Hitbox prefab and checking for that instead like so:

if(collide.gameObject.tag == "Hitbox")

I’m not sure if this will cause problems for me later, but it seems to work for now.

Edit 2:

It turns out that object’s name was being processed as “Hitbox(Clone)”. I followed the advice of an answer here and had the name written to the debug log.

OnCollisionEnter is a collision event, you want to access the collider component involved in that event. From my comments :

Debug.Log( "collide (name) : " + collide.collider.gameObject.name );
Debug.Log( "collide (tag) : " + collide.collider.gameObject.tag );
if(collide.collider.gameObject.name == "Hitbox")

(on further information) : Ah, yes, instantiated object append (clone) to the name. Do some renaming when instantiating :

var clone : GameObject = Instantiate ( ....
clone.name = "Hitbox";

is it possible to get your collider’s name?
like:
onTriggerEnter is on playercontroller
player collide with health pack
at this time, collider col.name is the health pack
but i want to know which collider from player collided with health pack