I have a 2D skeleton animation of human walk cycle - which is fine. I am trying hard to code that should STOP only hands animation but legs should not (on a player input - for example on space bar press) Is it possible to disable animation keyframes/curves/properties on some condition Or any other way to achieve this.
1 Answers
0
votes
Have multiple states in your Animation Controller. Let one state have both hands and legs animation, and the other have only legs animation. Transition from the first state to another by adding a parameter in your Animation Controller. Let the parameter be a bool.
Ex: From running animation to rest animation, have a bool stopRunning
and from rest animation to run animation, have a bool startRunning
So when the statRunning
bool is set, the character transits from rest animation to running animation, and when the stopRunning
bool is set, the character is put to rest.
Then in your code, when spacebar is pressed, call these functions
public void StopRunning() {
if (_PlayerAnimator.isActiveAndEnabled) {
_PlayerAnimator.SetBool("stopRunning", true);
_PlayerAnimator.SetBool("startRunning", false);
}
}
public void StartRunning() {
if (_PlayerAnimator.isActiveAndEnabled) {
_PlayerAnimator.SetBool("startRunning", true);
_PlayerAnimator.SetBool("stopRunning", false);
}
}