Two animations to a single gameObject

Hi, I have two animations, with the names “open” and “closed” would when entering the trigger animation to begin with the name “Open” and when you leave the trigger animation to begin with the “closed” name. I have the following script that works very well for “open” someone could help me out when the trigger the animation named “closed” start?
Below is my script, I tried to put a variable, but it did not work. help me

#pragma strict

//var ani1 : Animator;
var ani : Animator;
var sound : AudioClip;

function Start () {
	ani.enabled = false;
}

function OnTriggerEnter () {

	AudioSource.PlayClipAtPoint (sound, transform.position);
	ani.enabled = true;

	//Destroy(gameObject);
}


/*
function OnTriggerExit () {
	AudioSource.PlayClipAtPoint (sound, transform.position);
	ani1.enabled = true;
	//Destroy(gameObject);
}
*/

You’d better try getting deep into the learning section about Animation. You just switch on an animator component instead of controlling it.

Usually you would handle it like this:

function OnTriggerEnter () {
	ani.SetTrigger("open");
}

function OnTriggerExit () {
	ani.SetTrigger("close");
}

Of course you need to properly setup your animator controller to handle those triggers and transitions based on them.

Transitions and conditions are explained in Animator Controller video tutorial.

I needed the help of friends, to open and close a door with two animations, was not able to animator, because I could not make the Player open the door when entered the trigger and leave when she left. So I otherwise without animation control. Who is interested here what I got and it worked perfectly.

var  chestSound: AudioClip; // peito abertura clipe de som vai aqui
var  treasureChest: GameObject; // pré-fabricada arca do tesouro vai aqui
var  treasureChest2: GameObject;
function  OnTriggerEnter (col: Collider) 
{
 
if (col.gameObject.tag == "Player" )
 
		{ // verifica para ver que o nosso controlador de personagem com tag "Player" entrou no gatilho
		AudioSource.PlayClipAtPoint (chestSound, transform.position); // toca o nosso clipe de som na posição do colisor / gatilho
		treasureChest.GetComponent.<Animation>().Play ("box_open"); // reproduz a animação padrão aplicado ao nosso modelo treasurechest
		//Destroy (gameObject); // destrói o GameObject que tem esse script, então o nosso colisor, neste caso,
 		}
}

function  OnTriggerExit (col: Collider) 
{
 
if (col.gameObject.tag == "Player" )
 
		{ // verifica para ver que o nosso controlador de personagem com tag "Player" SAIU no gatilho
		AudioSource.PlayClipAtPoint (chestSound, transform.position); // toca o nosso clipe de som na posição do colisor / gatilho
		treasureChest2.GetComponent.<Animation>().Play ("box_close"); // reproduz a animação padrão aplicado ao nosso modelo treasurechest
		//Destroy (gameObject); // destrói o GameObject que tem esse script, então o nosso colisor, neste caso,
 		}
}