Need help with my animation script

I’m trying to make a simple script to open and close a door. I’m a noob when it comes to scripting but this is what I have made so far:

function OnMouseDown () {
animation.Play("open");
if (OnMouseDown) {
animation.Play("close");
}

}

But the script does understand that I want to make two different commands. This is what I want to achieve.

When I click on the door the door will open, and STAY open!
When I click on it again the door will close and stay that way until I click on it again.

All help is appreciated.

Thanks.

if (OnMouseDown) doesn’t make any sense.

You should set a boolean and test it:

var isOpen = false;

function OnMouseDown () {
 if (isOpen)
   animation.Play("close");
 else
   animation.Play("open");
}

you could use ray casting and colliders