- Home /
Question by
MrFalseEye · Aug 14, 2015 at 06:00 AM ·
animationtriggermechanimstate
Mechanim state triggers twice
I have a simple state machine as shown below
Idle -> Kick is simply triggered when player hits the B key. I've set Kick -> Idle with exit time 1 so that Kick gets played once and then automatically returns to the Idle state. This is the Kick -> Idle properties.
The thing is, Kick plays twice for some reason. I took a close look and found that Kick played once, then it returned to Idle for like 1 frame and then again returned to Kick to play the second time and then finally returned to Idle. I don't know if this is a bug or some mistake on my side.
This is the code to trigger Kick.
if(Input.GetKey(KeyCode.B))
{
anim.SetTrigger("kick");
}
Comment
Best Answer
Answer by MrFalseEye · Aug 14, 2015 at 10:06 AM
I changed Input.GetKey(KeyCode.B) to Input.GetKeyDown(KeyCode.B) and it worked!