Using mecanim to open doors

Hello, I have a game where I have to use mecanim in order to play open/close animation. I have set up a script attached to each door:

using UnityEngine;
using System.Collections;

public class DoorManager : MonoBehaviour {
	public enum DoorStateEnum { OPEN, CLOSED }
	public DoorStateEnum CurrentDoorState = DoorStateEnum.CLOSED;
	protected Animator animator;
	void Start()
	{
		animator = GetComponent<Animator>();
	}
	void OnCollisionEnter(Collision col)
	{
		if(col.gameObject.name == "Player")
		{
			CurrentDoorState = DoorStateEnum.OPEN;
		}
		else
		{
			CurrentDoorState = DoorStateEnum.CLOSED;
		}
	}

	void Update()
	{
		if (animator)
		{
			//get the current state
			AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
			if (stateInfo.nameHash == Animator.StringToHash("Opened") || stateInfo.nameHash == Animator.StringToHash("Closed"))
			{
				switch(CurrentDoorState)
				{
				case DoorStateEnum.OPEN:
					animation.Play("Opened"); 
					break;
				case DoorStateEnum.CLOSED:
					animation.Play("Closed"); 
					break;
				}
			}
		}
	}
}

But when I play the game it tells me that I have no animation by that name. I checked my files and yes they exist, yes they have animations, and yes I am writing their names correctly. This is how I know its got to be something I am setting wrong in mecanim. Here is an illustration of how my animator is set up for the doors.

Can anyoone help me figure out what is wrong here? Many thanks in advance!

http://unity3d.com/learn/tutorials/modules/beginner/animation/animator-scripting

I think you’ve misunderstood how the Animator component works. You don’t call individual animation clips to play; rather, you set parameters that cause the Animator to transition between various states, each of which is associated with an animation.

So, you need to create a bool parameter called and use this to transition between the open and closed states (it’s unclear from your screenshot what the current transition condition is, but I’m guessing it’s exit time.

When you use Mechanim (also known as Animator), you can’t call the animations like you used to. You need to trigger the various Animator states with the variables you can set up. Since you already have an int variable set up (“Index”), I’ll use that in the example. In this example “Index” is the condition of the transitions (js):

private var Anim : Animator;

function Start ()
	{
	Anim = gameObject.GetComponent(Animator);
	Anim.SetInteger("Index", 0); //-- this would tigger the appropirate transition.
	}

You should also read up on Animators: Unity - Manual: The Animator Controller Asset