anim.SetBool not working?,Anim.setbool not working?

This is my first time making a game using unity or C# so it could be an easy fix but, as said in the title i cannot figure out how to set the animation bool to true.
Here is my code
public void hit()

{
if (Input.GetKeyDown(KeyCode.RightControl))
{
        anim.SetBool("chop", 1);
}
else
{
        anim.SetBool("chop", 0);
}
}

This code is meant to trigger the attack animation for my character but the bool remains false.,This is my first time making a game using unity or C# so it could be an easy fix but, as said in the title i cannot figure out how to set the animation bool to true.
Here is my code
public void hit()

{
if (Input.GetKeyDown(KeyCode.RightControl))
{
        anim.SetFloat("chop", 1);
}
else
{
        anim.SetFloat("chop", 0);
}
}

This code is meant to trigger the attack animation for my character but the bool remains false.

First of all I would recommend to check if the if-statement is working.

if (Input.GetKeyDown(KeyCode.RightControl))
     {
             Debug.Log("key clicked -- chop = true");
             anim.SetBool("chop", 1);
     }

Then the value is a boolean. So to just be sure please replace the number 1 and 0 with true and false.


Next question: Does you have set the reference object of ‘aim’ in the inspector or by script? I think you know it, but for safety:

  1. You can set the animator public:

    public Animator anim;

  2. you can set the reference by script:

    private Animator anim;

    void Start(){
    anim = gameObject.GetComponent();
    Debug.Log(anim);
    }

I hope some of my advices helped. Happy coding :wink: