Basically I want to run an animation once when I press a key. And no matter how long the key is pressed I want to run it once completely and then transition automatically back to idle state.
I really have tried to find a solution regarding to this, because there are many similiar questions on the web, but I couldn’t find anything that explains this in detail, because I’m completely new to Unity.
if (Input.GetKeyDown (KeyCode.E)) {
anim.SetBool ("Kicking", true);
}
if(anim.IsInTransition(0) && anim.GetNextAnimatorStateInfo(0).nameHash == kickStateHash){
anim.SetBool("Kicking", false);
}
This is basically the code, the problem is that when I press ‘E’ it doesn’t run ‘Kick’ all the way through but cuts it in the middle. I know why it’s doing this, but don’t know how to fix it.
I also tried this:
if (Input.GetKeyDown (KeyCode.E)) {
anim.SetBool ("Kicking", true);
}
if (anim.GetCurrentAnimatorStateInfo(0).nameHash == kickStateHash) {
} else {
anim.SetBool ("Kicking", false);}
But it doesn’t work at all. (I don’t get any errors but the animation isn’t -visibly- playing)
I also tried with a Trigger instead of a Bool, but then again the animation only plays halfway and then transitions back to Idle.