if(animation.clip.name.Contains(""))

Hi there,

I’ve been having a little problem,
I’m creating a script to help open doors, but first I need to get a couple of AnimationClips, each one containing a specific word(In this case “Open” and “Close”), however I’m having trouble.
The if() statements in my script only seem to be accessing whichever AnimationClip is in the part that is highlighted Red in the inspector but I need it to get my AnimationClips that are highlighted Yellow in the inspector.

I’m sure that I’m missing something really simple.
Anyway, even the slightest bit of help would be greatly appreciated.
Thanks In advance.

public class DoorScript : MonoBehaviour
{
	GameObject Door;
	public AnimationClip OpenAnimation;
	public AnimationClip CloseAnimation;
	void Start()
	{
		Door=gameObject;
		if(Door.GetComponent<Animation>().name.Contains("Open"))
		{
			Debug.Log("FoundOpen");
		}
		if(Door.GetComponent<Animation>().name.Contains("Close"))
		{
			Debug.Log("FoundClose");
		}
	}
}

I’m trying to find a way that the script can automatically find the two animations, without having to place them each time using the inspector. So far I have come up with this,

public class DoorScript : MonoBehaviour
{
	GameObject Door;
	Animation Anim;
	bool Open=false;
	AnimationState OpenAnimation;
	AnimationState CloseAnimation;
	void Start()
	{
		Door=gameObject;
		Anim=GetComponent<Animation>();
		foreach(AnimationState state in Anim)
		{
			if(state.name.Contains("Open"))
			{
				Debug.Log("FoundOpen");
				OpenAnimation=state;
				OpenAnimation.name=("Open");
			}
			if(state.name.Contains("Close"))
			{
				Debug.Log("FoundClose");
				CloseAnimation=state;
				CloseAnimation.name=("Close");
			}
		}
	}
	void Interact()
	{
		Open=!Open;
		if(!Open)
		{
			animation.Play("Close");
		}
		else
		{
			animation.Play("Open");
		}
	}
}

This seems to work the way I wanted it to.
Thanks for your help all.