Play animations in animator when buttons are pressed

Hello everyone! I’m just going to go straight to the question so I can save you all some time!
I’m trying to switch from my “Idle” animation to a “growl” animation when I press a button. I have everything set up in the character’s animator. The “growl” animation is in the animator connected as a transition and it has a bool condition. When the player presses the button I want the animation should play once and when the player presses the button again, it should play again. Sounds easy right? Well these small task has been haunting me for about a week now. Please help me!

This is my Script:

 #pragma strict

var animator : Animator;
 
 function Start ()    
 {
     animator = GetComponent("Animator");
 }
 

function Update ()
{     
    if(Input.GetButtonDown("PS4_Triangle")) 
    {
        animator.SetBool("Triangle", true);
    }
    else
    {
        animator.SetBool("Triangle", false);
    }    
 }

The thing with this code is that when I press the button that I want it rapidly enables and disables it so quickly that the animation doesn’t get a chance to play. Can you please explain why it might be doing this? Is there something wrong with my code? I’m using Java Script. Thanks in advance.

Guys, thank you so much for your help! With the help of all of you I was able to solve this issue. I cant thank you guys enough. This is an amazing community!

This script is what did it.

#pragma strict

var animator : Animator;

function Start () {
animator = GetComponent(“Animator”);
}

function Update () {

 if(Input.GetButtonDown("PS4_Triangle")) {
  
     animator.SetBool("Triangle", true);


 
}

else if (animator.GetCurrentAnimatorStateInfo(0).IsName(“NameofAnimation”))
{
animator.SetBool(“Triangle”, false);
}
}