how to make an animation to play when a int has a certain value, and pressing space key?

i’m trying to do that, but its not working, heres the code:

    void Update()
    {
        if (Input.GetKeyDown("space") && (IDdaArma == 0))
        {
            animation.Play("ArmaPadraoAtirando");
        }
    }
}

looks like the void update is ignoring what i did in the “if” code, and only does the animation code thing. the animation keeps repeating if i keep the loop time option turned on, if i turn it off the animation only plays at the start of the scene and never plays again. i want to a certain animation file plays when the value of the int (IDdaArma) is 0, and if the value is 1, another animation file plays when pressing space.

So it depends on , “where is your integer” , in the animation controller or in your class?

if it is in your animation controller,
here is how it works to set and get the value:

        anim.SetInteger("integerName", 1);
        anim.GetInteger("integerName");

also, your “if” loop is not correct:

    void Update()
    {
        if (Input.GetKeyDown("space") && IDdaArma == 0)
        {
            animation.Play("ArmaPadraoAtirando");
        }
    }

if your variable is in your .cs file, this should work,
if it is in your animation controller, instead of IDdaArma you should get the animation controller integer value there