MissingComponentException: There is no 'Animation' attached to the "Capsule" game obj

Hello,

I am new to Unity. And as “soft” landing, I am struggling this error for few days now.

I saw a lot of posts on the subject, but no suggestion fixed that.

I am attaching the screen shot of my scene:

And here is the code for the SwingAnimation.cs script:

using UnityEngine;
using System.Collections;

public class SwingAnimation : MonoBehaviour {
    public AnimationClip AttackAnimationClip;
	// Use this for initialization
	void Start () {
	
	}
	
	// Update is called once per frame
	void Update () {
        if (Input.GetMouseButton(0))
        {
            animation.Play(AttackAnimationClip.name);
        }
	}
}

What is wrong with this??

Thanks in advanced

You added the wrong component to the capsule. You added an Animator component which is for the newer Mecanim system. But you’re using in your script an Animation component. So you have th remove the Animator and add the Animation component

Thanks. This is what I was suspecting, but this component is being added by drag and drop operation and I couldn’t find where Animation component is.

Press the Add Component button in the Inspector and type in Animation. Thats all.