Single Action animation problem.

Hi everyone, I have a little problem I have a set up of animations it all works well with walking, but when I want to play a single action like Interact with something it didn’t work correctly, It don’t work at all or if I change statement just to if without else if it loops and never stops.

Here is the Script I use for Animation:

using UnityEngine;
using System.Collections;
[RequireComponent(typeof(Animator))]
public class MainControlAnimation : MonoBehaviour
{
    public float animSpeed = 1.5f;
    public float lookSmooth = 3f;
    private Animator animControl;
    private AnimatorStateInfo BaseLayer;
    private AnimatorStateInfo Layer2;
    static int idleState = Animator.StringToHash("Base Layer.Idle");
    static int walkForwardstate = Animator.StringToHash("Base Layer.walkForward");
    static int actionButton = Animator.StringToHash("Layer2.actionButton");
    private AnimatorStateInfo currentBaseState;
    private AnimatorStateInfo currentLayer2State;
    void Start()
    {
        animControl = GetComponent<Animator>();
        if (animControl.layerCount == 2)
        {
            animControl.SetLayerWeight(1, 1);
        }
    }

    // Update is called once per frame
    void FixedUpdate()
    {
       
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        animControl.SetFloat("Speed", v);
        animControl.SetFloat("Direction", h);
        animControl.speed = animSpeed;
        currentBaseState = animControl.GetCurrentAnimatorStateInfo(0);
        if (animControl.layerCount == 2)
            currentLayer2State = animControl.GetCurrentAnimatorStateInfo(1);
       
         else if (currentBaseState.nameHash == idleState)
        {
            if (Input.GetButtonDown("actButton"))
            {
                animControl.SetBool("Action", true);
            }
        }
       
        if (currentLayer2State.nameHash == actionButton)
        {
            animControl.SetBool("Action", false);
        }
        }
    }

In the animation controller I set up everything like it was sad for one single action, in this video tut:

if you are using unity 5.# you can now use “triggers” in the animator instead of bools when you want something to only transition once

I want this animation play many times but only when button is pressed with Input.GetKeyDown(“example”), if triggers allow this I will try them.

I tried Trigger it worked many thanks for your advise it worked even with a less code.

public class MainControlAnimation : MonoBehaviour
{
    public float animSpeed = 1.5f;
    public float lookSmooth = 3f;
    private Animator animControl;
    private AnimatorStateInfo BaseLayer;
    private AnimatorStateInfo Layer2;
    static int idleState = Animator.StringToHash("Base Layer.Idle");
    static int walkForwardstate = Animator.StringToHash("Base Layer.walkForward");
    static int actionButton = Animator.StringToHash("Layer2.actionButton");
    private AnimatorStateInfo currentBaseState;
    private AnimatorStateInfo currentLayer2State;
    void Start()
    {
        animControl = GetComponent<Animator>();
        if (animControl.layerCount == 2)
        {
            animControl.SetLayerWeight(1, 1);
        }
    }

    // Update is called once per frame
    void FixedUpdate()
    {
       
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        animControl.SetFloat("Speed", v);
        animControl.SetFloat("Direction", h);
        animControl.speed = animSpeed;
        currentBaseState = animControl.GetCurrentAnimatorStateInfo(0);
        if (animControl.layerCount == 2)
            currentLayer2State = animControl.GetCurrentAnimatorStateInfo(1);
       
       
            if (Input.GetButtonDown("actButton"))
            {
                animControl.SetBool("Action", true);
            }
        }
    }