简体   繁体   English

Unity 2D动画部分运行

[英]Unity 2D animation running partially

I have a 2D skeleton animation of human walk cycle - which is fine. 我有一个人类步行周期的2D骨架动画-很好。 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. 我正在尝试编码应该仅停止动画而不停止腿部的代码(在玩家输入时-例如在空格键按下时)是否可以在某些情况下禁用动画关键帧/曲线/属性,或者通过其他任何方式来实现此目的。

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 例如:从运行动画到静止动画,都有一个bool stopRunning ,从静止动画到运行动画,有一个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. 因此,当设置了statRunning bool时,角色将从静止动画过渡到正在运行的动画,而当设置了stopRunning bool时,角色将处于静止状态。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM