Destroy object upon player collision with a different object

Hey everyone,
I am very new to programming and i need some help. What i want is for my player to collide with a gameObject that will act as a key, and upon collision a different gameObject (a door) will get destroyed.

I began using the script found here just to learn: 3D Physics - Unity Learn

However, that only destroyed the colliding gameObject, which is not what i want. So, i modified it a bit. No errors, but the collision doesn’t seem to register when my player touches the “key” gameObject.

Any help appreciated.

JS:

var thing : GameObject;

function OnCollisionEnter (col : Collision) {

if(col.gameObject.tag == "Player")
{
    Destroy(thing.gameObject);
}

}

You probably want to destroy the key as well as the door right?

You are close.

Make sure the key has this script attached, as well as a box collider. In the inspector for the key go to its collider and check “isTrigger.” Also drop the door from the hierarchy into the field for “thing”. That is so the key knows which door to destroy.

Now the script on the key should be:

void OnTriggerEnter(Collider other)
{
    if (other.gameObject.CompareTag("Player"))
    {
         Destroy(thing);
         Destroy(gameObject); // if you want to destroy the key as well
    }
}

The player needs a collider as well. Not set to trigger.