Button Box Door Collision

How do I type a code which is applied to the button (Cylinder shape with a collider)which states if the GameObjects (I want two or more different things) collides with the button (itself), it says that a GameObject (Door) plays animation 1(Opening) and then if the Door senses no collision, it plays animation 2(Closing). I want it to be easy and no Fixed gameobjects e.g. Gameobject.Tag==“Something”. I hope this is making sense. I’m learning Javascript. Thanks.

You are tring to make a physical button in game. Am i right ? if it is yes

var opendoor: Animation;
var closedoor: Animation;

function OnCollisionEnter(collision : Collision) {
   
  if  (collision.gameObject.tag=="myTag")
  
  {
  
  opendoor.Play();
  
  }

}

function OnCollisionExit(collision : Collision) {
   
  if  (collision.gameObject.tag=="myTag")
  
  {
  
  closedoor.Play();
  
  }

}

Sorry but I’m not seeming to get it correct!
Here’s the script applied to the button:

var opendoor: Animation;
var closedoor: Animation;

function OnCollisionEnter(collision : Collision) {

if (collision.gameObject.tag==“Player”)

{

animation.Play(“opendoor”);

}

}

function OnCollisionExit(collision : Collision) {

if (collision.gameObject.tag==“Player”)

{

animation.Play(“closedoor”);

}

}

Here is a picture to show the door and the button.