统一5.1动画控制器未转换 [英] Unity 5.1 Animator Controller not transitioning

查看:145
本文介绍了统一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动画控制器未转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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