How can I setup my bool/trigger in animator?

Hi, I’m new to Unity (and C#) and trying to link my bool and my animation in animator to play correctly.

I have my bool:

bool shoot = Input.GetButtonDown(“Fire2”);

And I have my animation set up on the player and it is playing (just looping infinitely despite the looping box being unchecked for the animation.

How can I get my bool to activate the parameter “shoot” in animator? I’ve tried to set a bool and a trigger, but can’t seem to get either to play the animation once on button press (“Fire2”) and then set to false. Any help would be greatly appreciated!

Here is the snippet of code that worked for me in case someone comes across this with the same problem:

	bool shoot = Input.GetButtonDown ("Fire2");  //Attack button and animation
					
	if (shoot) {
		Animator animator = GetComponent<Animator>() as Animator;
		animator.SetTrigger("Attack");