Hi everybody i am making a little game to learn the 2d in unity.
I could create a character with various states,his states are “idle” “run” and “punch”.
My problem is when from the idle state i do a punch it gets stuck at the last frame and it doesn’t return in idle,instead when from the run state i give a punch at the end of the punch animation the player’s sprite returns to the run state.
Here’s the part of code that handles the punch.
void Update()
{
if (Input.GetKeyDown(KeyCode.X))
{
animator.SetBool("punch", true);
}
if (!animator.GetCurrentAnimatorStateInfo(0).IsName("punch") && !Input.GetKey(KeyCode.A) && !Input.GetKey(KeyCode.D))
{
animator.SetTrigger("idle");
}
else if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.D))
{
animator.SetTrigger("running");
}
}
The parameters of the player’s animator are
- Trigger “running”
- Trigger “idle”
- Bool “punch”
The conditions of the transition from punch to idle are
- If the Trigger is “idle”
- if the Bool “punch” is false
- the exit time is 0.90
What is wrong?
Thanks in advance