problem with chest animation

So just need some help, i have two animations in my scene and when i activated one with left click this one plays as well i want this one to play when i click on the object itself and just wondering how to do it ?
any advice would be greatly appreciated

var open = false;
var activated = false;

function Update(){
  if (Input.GetKeyDown("x")){
    activated = true;
  }
  if (activated && !open && Input.GetButtonDown("Fire1")){
    animation.Play();
    open = true;
  }
}
  • Add a collider to the object (Box collider probably)
  • Write a function called OnMouseDown() that plays your animation.