Unity 的 Animation 组件(不是 Animator)使用的是 Legacy 动画系统。而从 Unity 4 开始,新导入的动画剪辑默认是为 Mecanim 动画系统(使用 Animator) 设计的。
在这里插入图片描述
在对应的模型里面添加相应的动作,需要记得删除animator组件。
在这里插入图片描述
animation是待机动作。
animations选择后去c#里面编写脚本

    void Update()
    {
        float horizontal = Input.GetAxis("Horizontal");
        float vertical = Input.GetAxis("Vertical");
        Vector3 dir = new Vector3(horizontal, 0, vertical);
        if (dir != Vector3.zero)
        {
            transform.rotation = Quaternion.LookRotation(dir);
            if (!animation.IsPlaying("run")) // 避免重复播放
            {
                animation.Play("run");//animations里面对应的动作
            }
            //朝前方移动
            transform.Translate(Vector3.forward*2*Time.deltaTime);
        }
        else
        {
            if (!animation.IsPlaying("idle")) // 避免重复播放
        {
            animation.Play("idle");//animations里面对应的动作
        }
        }
        
    }
Logo

汇聚全球AI编程工具,助力开发者即刻编程。

更多推荐