Unity player collision with object?

I have a player and I’m trying to have it detect a collision with an object. The object I’m trying to collide with has a mesh collider and a rigid body and the player has a character controller with a capsule collider. But it will not detect a collision. I’m using this script.

function OnCollisionEnter(collision : Collision) {
    // Debug-draw all contact points and normals
    for (var contact : ContactPoint in collision.contacts) {
        Debug.DrawRay(contact.point, contact.normal, Color.white);
    }
    
    // Show the car has been hit     
    if (collision.relativeVelocity.magnitude > .01)
        print("Object Hit");
}

Also how can I set it up to only detect a collision from a certain object.

Use OnControllerColliderHit() instead of OnCollisionEnter() for a character controller.

Here’s a link