- Home /
Can't switch through 2 animation states in one frame
I'm trying to change states in animator like this
if(Input.GetKeyDown(KeyCode.Space)){
anim.SetBool("idlehands", false);
anim.SetBool("default", true);
anim.SetBool("default", false);
anim.SetBool("idleFireaxe", true);
}
and it is not working but if i make it like this
if(Input.GetKeyDown(KeyCode.Space)){
anim.SetBool("idlehands", false);
anim.SetBool("default", true);
} else if (Input.GetKeyDown(KeyCode.B)){
anim.SetBool("default", false);
anim.SetBool("idleFireaxe", true);
}
and press space then b it works as it should work. So what is the problem? Why i cannot change states the way i want? Please help!
Remember that the code you have there is inside update, and update runs every frame, if your game goes at 60 frames per second then update gets called 60 times per second, if an animation lasts 3 seconds then the animation is performed over 180 frames. It isn't working like you want because you are trying to change the state of the animation twice in just one frame, but animation is something that happens over multiple frames so you can't expect it to behave correctly.
Basically you are not giving the animation the time it needs to be played.
But in default state i have no animation, it is empty