need help playing animation

I have a problem with a “play animation” code

heres the code;

#pragma strict

var steveState = 0;
var Anim : AnimationClip;

function Update () {

if(Input.GetKeyDown("up")){
animation.Play("Anim");
 }
}

as of right now whenever I press the up key animation will play. I have my animation attached to my character and my code but the console gives me an error that says : MissingComponentException: There is no ‘Animation’ attached to the “steve” game object, but a script is trying to access it.
You probably need to add a Animation to the game object “steve”. Or your script needs to check if the component is attached before using it.
UnityEngine.Animation.Play (System.String animation)
steve ai.Update () (at Assets/steve ai.js:8)

I got an answer fixing this error but now I have new ones like this:
The AnimationClip ‘walk foward’ used by the Animation component ‘steve’ must be marked as Legacy.
UnityEditor.DockArea:OnGUI()

and

Default clip could not be found in attached animations list.

Thanks :slight_smile:

The error is telling you you need an Animation component rather than just the Animation file itself. Go to Add Component → Miscelleneous → Animation (not “Animator”, that’s different).

You should also just drag the Animation clip onto the “Animation” clip field in that component. It also makes life easier.