How do I play an animation on click correctly?

I want to play the melee animation when I click the left mouse button, but for some reason, I can’t play the animation after I click. Here is my code:

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

public class AnimationController : MonoBehaviour
{
    public Animator anim;
    
    void Start()
    {
        anim = GetComponent<Animator>();
    }

    void Update()
    {
        if (Input.GetMouseButton(0))
        {
            anim.Play("Melee");
        }
    }
}

Scripts look good to me. Please check below two points:

  1. Did you assign the correct animator controller in the Animator(In Inspector) which should be added to the game object?
  2. In the Animator window did you added the correct animation clip(“melee” or “Melee” the name should be same ) which you wanted to play?

If nothing from above helps could you please mention the exact Error or Warning which you are getting.

screen shot of animator window while in play mode?