Legacy animation not playing - no errors?

I am trying to animate my character with the legacy animation system. There are no errors, and the animation clip appears in the ‘animation’ component, but the animation doesn’t play. I have a script to make it play here:

using UnityEngine;
using System.Collections;

public class playerAnimation : MonoBehaviour {

	public AnimationClip anim;
	
	void Update (){
		if(Input.GetKeyDown(KeyCode.A)){
			animation.clip = anim;
			animation.Play();
		}
	}

}

I was having a similar problem, very frustrating. I found that calling a different overload with explicit playmode defined in Animation.Play/CrossFade made it work.

So instead of just anim.Play(“name”) try using

anim.Play("name", PlayMode.StopAll);

or

anim.CrossFade("name", 0.5f, PlayMode.StopAll);