- Home /
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.
Answer by DevManuel · Mar 03, 2021 at 08:29 AM
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;
you can set the reference by script:
private Animator anim; void Start(){ anim = gameObject.GetComponent<Animator>(); Debug.Log(anim); }
I hope some of my advices helped. Happy coding ;-)
I've got the same problem and it doesn't work for weird reasons. I just assigned 1 to the "temp" parameter and when I print it in the next line it still says 0. It's super simple code! just three lines! I can't even find out what's the problem
Your answer
![](https://koobas.hobune.stream/wayback/20220613030119im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Door Script 1 Answer
How do I check if all booleans in an array are true? 2 Answers
Trigger won't read my Bool change 1 Answer
Trying to create a function that returns a bool 2 Answers
BitShifting and boolean functions 1 Answer