Hi, I’m new to Unity (and C#) and trying to link my bool and my animation in animator to play correctly.
I have my bool:
bool shoot = Input.GetButtonDown(“Fire2”);
And I have my animation set up on the player and it is playing (just looping infinitely despite the looping box being unchecked for the animation.
How can I get my bool to activate the parameter “shoot” in animator? I’ve tried to set a bool and a trigger, but can’t seem to get either to play the animation once on button press (“Fire2”) and then set to false. Any help would be greatly appreciated!
Trigger is what you want for a "one-shot" state change trigger. What exit conditions do you have in the shooting animation state in the animator? Assuming these are met, it should transition straight away once the animation has played.
– tanoshimiHi tanoshimi and thanks for the comment! It looks like I had a bunch of views before you chimed in, but no advice :) It turns out the trigger is what I wanted and I have the exit conditions set as the name of my trigger in the animator parameters. It's mostly working now and I think if I just adjust my animations a bit, it'll be fine. What I ended up doing was calling for the animator using GetComponent (again) right after my bool, then I could use SetTrigger without any problems for the animation!
– Danao