Animation Not playing

Animation Not playing. why? error CS1061: Type UnityEngine.Component' does not contain a definition for Play’ and no extension method Play' of type UnityEngine.Component’ could be found. Are you missing an assembly reference?`using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HeadHit : MonoBehaviour {

%|-1814071339_1|%
void Start () {
%|1205629864_3|%
%|1624323751_4|%

%|1732494877_6|%
void Update () {
if (Input.GetKey(KeyCode.E)) {
animation.Play (“Hit0”);
%|620421206_10|%
%|765253691_11|%
%|-1072008687_12|%
}
%|1153412139_14|%
}`

Try explicitly referencing your animator component.
Instead of using the shortcut ‘animation’, try creating an Animation variable, and tell THAT to play. Try…

public Animation _anim;

void Start ()
{
    _anim = gameObject.GetComponent<Animation>();
}

// Update... If (input ... )
    _anim.Play("AnimationNameHere");

I’m not certain this will solve your problem, but it should work. I haven’t seen the specific error you’ve shown before, but it seems not to realize you are trying to reference the legacy animation component.

Also, unless you are working on an old project that is firmly entrenched in the legacy animation system, I would highly recommend switching to the new mecanim animator system. It requires a bit of learning to set up the animator controller transitions, but I find it is really much easier to use once you catch on to that stuff.

You want to get the animator that contains those 2 animations, then when desired key is down (don`t use get key, because it will load the animation every frame while holding) tell the animator to play the desired animation. (make sure the strings are exactly the same)

try this:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class HeadHit : MonoBehaviour {

	public Animator animator; //assign the animator here.

	// Use this for initialization
	void Start () {

	}

	// Update is called once per frame
	void Update () {
		if (Input.GetKeyDown(KeyCode.E)) {
			animator.Play ("Hit0");
		}
		if (Input.GetKeyDown(KeyCode.Q)) {
			animator.Play ("Hit1");
		}
	}
}

hello everyone, i know this is very old question , but i had similar problem few days ago. So in my case , i accidentally created a script called “Animator”. Now my all animations in project called this script (this script is empty), so as result i got lot of errors .
so just look in your project, if you had also an script named as “Animator” which is created by you and delete it because it is conflicting the pre made classes of unity.
Sorry for my bad English.
Hope this is useful.