- Home /
C# animator bool
Hello, just wondering if anyone can take a look at my code and tell me why my animation aint playing on input.getbutton("Fire1)" please. Im trying to set a bool which gets true when input is pressed, else it's false, so the animation will play according to that. `public class GunAnimation : MonoBehaviour {
private Animator animator;
void Start ()
{
}
void Update ()
{
if (animator)
{
AnimatorStateInfo stateInfo = animator.GetCurrentAnimatorStateInfo(0);
if(stateInfo.nameHash == Animator.StringToHash("gunIdle"))
{
if(Input.GetButton("Fire1"))
animator.SetBool("gunShoot", true );
}
else
{
animator.SetBool("gunShoot", false);
}
}
}
}
I tried to check the unity script reference, the videos with no luck...
Answer by Sveyh · Apr 05, 2014 at 06:11 AM
Hey Sveyh, I had the same problem and I solved it by typing public class GunAnimation : MonoBehaviour { void Start () { } void Update () { if (Input.GetButtonDown ("Fire1")) { Shoot skott = GetComponentInChildren<Shoot>(); if(skott.ammoPerClip > 0) { animation.Play ("shootanim"); } } } }
Your answer
Follow this Question
Related Questions
Animation transition not recognized while holding multiple keys 0 Answers
How to prevent an animation from triggering more than on due to fast clicking? 2 Answers
Using MRT HolographicButton results in "Animator is not playing an AnimatorController" 0 Answers
Animator and animations issue 1 Answer
Problem with Animator Transitions 0 Answers