Unity 2D 动画部分运行 [英] Unity 2D animation running partially

查看:28
本文介绍了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 和从休息动画到运行动画,有一个布尔值 startRunning

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

所以当statRunning布尔值被设置时,角色从静止动画过渡到运行动画,而当stopRunning布尔值被设置时,角色被置于静止状态.

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 动画部分运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆