Animation won't play, legacy issue?

I’m getting this error when I’m trying to play my animation made in the animation window. It’s a simple move and rotation animation on a game object. Other threads I found said to change the rig to legacy mode but I don’t have a rig, I’m just trying to animate a game object.

anim.Play(“HammerHit”);

The animation state “HammerHit” could not be played because it couldn’t be found! Please attach an animation clip with the name ‘HammerHit’ or call this function only for existing animations.

I definitely have the animation with that name and it’s in the inspector window animation component.

is anim a reference to the Animation component?
ie
Animation anim = gameObject.animation;
or
Animation anim = gameObject.GetComponent();

Correct case and spacing?

The latter.