本文介绍了Unity 2D动画部分运行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个人类步行周期的2D骨架动画-很好。我正在尝试编写仅应停止手部动画但不能停止腿部的代码(在玩家输入时(例如在空格键上))
是否可以在某些情况下或其他条件下禁用动画关键帧/曲线/属性

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.

推荐答案

动画控制器中有多个状态。让一种状态同时具有手和腿的动画,而另一种状态仅具有腿的动画。通过在动画控制器中添加参数,可以从第一种状态转换为另一种状态。令参数为布尔值。

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.

例如:从运行动画到其余动画,都有一个布尔值 stopRunning ,从静止动画到运行动画,都有bool startRunning

Ex: From running animation to rest animation, have a bool stopRunning and from rest animation to run animation, have a bool startRunning

因此,当 statRunning bool为设置后,角色从静止动画过渡到运行动画,并且当设置 stopRunning bool时,角色将进入静止状态。

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

这篇关于Unity 2D动画部分运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 02:04