统一5.1动画控制器未转换

编程入门 行业动态 更新时间:2024-10-28 10:30:53
本文介绍了统一5.1动画控制器未转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我已经创建了一个动画控制器(名为播放器),并将其分配给我的人形化身的动画字段,以及简单的动画状态与适当的过渡。请参阅连接的两个图像。

I have created an Animator Controller (called Player) and assigned it to the Animator field of my humanoid avatar, as well as simple animation states with suitable transitions. Please see the two attached images.

我附上一个脚本,包含以下code,我的头像游戏的对象,但我不知道我失踪或者做错了,从过渡待机到走不会发生,即使我可以看到速度变量增加时,我preSS 是W 。

I have attached a script, containing the following code, to my avatar game object, but I wonder what I am missing or doing wrong that the transition from Idle to Walk does not take place, even though I can see that the speed variable increases when I press W.

可能有人请帮助我理解这个问题?

Could someone please help me understand the problem?

using UnityEngine; using System.Collections; public class CharAnim : MonoBehaviour { private Animator animator; float speed; void Start() { animator = GetComponent<Animator>(); } void Update() { animator.SetFloat( "speed", Input.GetAxis("Vertical") ); if ( Input.GetKeyDown( KeyCode.W ) && ( speed > 0.5f ) ) { animator.SetTrigger("Walk"); } else { animator.SetTrigger("Idle"); } } }

X

推荐答案

在code中的问题是, animator.SetTrigger(走); 变所谓在单个帧时,pressed键和 animator.SetTrigger(空转); 被调用的其他帧

The problem in your code is, animator.SetTrigger("Walk"); gets called in a single frame when you pressed the key and animator.SetTrigger("Idle"); gets called for the rest of the frames.

试着改变 Input.GetKeyDown(主要codeW)到 Input.GetKey(主要codeW)。前者返回true只有一次,瞬间,当你preSS下来的关键,而后者则返回true,直到你松开按键。是这样的:

Try changing Input.GetKeyDown( KeyCode.W ) to Input.GetKey( KeyCode.W ). The former returns true only once, the instant when you press down the key, whereas the latter returns true until you release the key. Something like :

void Update () { if(Input.GetKey(KeyCode.W)) { animator.SetTrigger("Walk"); } else animator.SetTrigger("Idle"); }

在一个侧面说明,你不需要速度在变量动画来触发动画走,既然你已经在做,使用是W 。

On a side note, you don't need the speed variable in the Animator to trigger walk animation, since you are already doing that using W.

空闲 - >步行

走 - >空闲

更多推荐

统一5.1动画控制器未转换

本文发布于:2023-10-26 10:50:58,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1529918.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:控制器   动画

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!