how can I trigger my animation through script?

I just have a simple gun setup and I want to a recoil animation. I have made the animation that simply rotates the gun upwards and downwards quickly however I don’t know how to trigger it through script. BTW the animation is supposed to play when the gun is shot and I am using root motion.

set animation rig to legacy

     public GameObject exampleObj;

public void Update()
{
        if (Input.GetKeyDown("e"))
        {
        exampleObj.GetComponent<Animation>().Play("ObjectAnimation");
        }
}