Unity 2D animation running partially

孤街醉人 提交于 2019-12-12 03:16:01

问题


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:


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);
        }
    }


来源:https://stackoverflow.com/questions/38529542/unity-2d-animation-running-partially

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!