Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/unity3d/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Animation Unity 5.1动画师控制器未转换_Animation_Unity3d - Fatal编程技术网

Animation Unity 5.1动画师控制器未转换

Animation Unity 5.1动画师控制器未转换,animation,unity3d,Animation,Unity3d,我已经创建了一个动画师控制器(称为播放器),并将其分配给我的人形化身的动画师字段,以及具有适当过渡的简单动画状态。请参阅所附的两张图片 我在我的阿凡达游戏对象上附加了一个包含以下代码的脚本,但我想知道我遗漏了什么或做错了什么,从Idle到Walk的转换没有发生,即使我可以看到speed变量在我按下W时会增加 有人能帮我理解这个问题吗 using UnityEngine; using System.Collections; public class CharAnim : MonoBehaviou

我已经创建了一个
动画师控制器
(称为
播放器
),并将其分配给我的人形化身的
动画师
字段,以及具有适当过渡的简单动画状态。请参阅所附的两张图片

我在我的阿凡达游戏对象上附加了一个包含以下代码的脚本,但我想知道我遗漏了什么或做错了什么,从
Idle
Walk
的转换没有发生,即使我可以看到
speed
变量在我按下
W
时会增加

有人能帮我理解这个问题吗

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");
      }
    }
}
使用UnityEngine;
使用系统集合;
公共类特征:单一行为
{
私人动画师;
浮动速度;
void Start()
{
animator=GetComponent


代码中的问题是,
animator.SetTrigger(“Walk”);
在按下键时在单个帧中被调用,而
animator.SetTrigger(“Idle”);
在其余帧中被调用

尝试将
Input.GetKeyDown(KeyCode.W)
更改为
Input.GetKey(KeyCode.W)
。前者仅在按下键的瞬间返回true一次,而后者在松开键之前返回true。类似于:

void Update ()
{
    if(Input.GetKey(KeyCode.W))
    {
        animator.SetTrigger("Walk");
    }
    else            
        animator.SetTrigger("Idle");
}
另一方面,您不需要使用
Animator
中的
speed
变量来触发行走动画,因为您已经在使用
W
进行此操作

空闲->步行

步行->空闲

{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);
}
其他的
设置触发器(“空闲”);
}{
if(Input.GetKey(KeyCode.W))
{
设置触发器(“行走”);

谢谢尼米什。我做了你建议的更改,但是