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!