使用animation找不到动画,报错The animation state *** could not be played because it couldn‘t be found!

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里面对应的动作
        }
        }
        
    }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值