通过脚本循环动画?统一二维

Looping Animations Through A Script? Unity 2D

这可能不像标题所说的那样。

但我基本上是想通过脚本来播放动画。一切顺利,出现错误

ArgumentException: Legacy clips cannot be used in Playables.

你也能帮我吗?它正在播放,但我已将循环设置为 true 并且出于某种原因,它不会循环。有没有办法通过脚本循环播放动画?

到目前为止,这是我的代码:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class playerMovement : MonoBehaviour
{
    public Rigidbody2D rb;
    public float moveSpeed = 1f;
    public Animation idleAnim;


    public void Start () {
        idleAnim.Play();
    }
    public void FixedUpdate()
    {
        if( Input.GetKey("a")) {
        rb.AddForce(Vector2.left * moveSpeed);
        }

        if ( Input.GetKey("d")) {
        rb.AddForce(Vector2.right * moveSpeed);
        }
    }

}

感谢您的帮助!

(如果你没注意到,我正在创建一个空闲动画)

您应该将动画标记为循环,select 动画资产并在检查器中将标志设置为 true。此外,您应该使用 Animtor 组件,向其添加空闲动画,添加另一个空状态,制作一些布尔参数以触发空闲动画和空动画状态之间的转换,例如将其称为“isIdle”,(您可能会添加将来会有更多动画状态,例如移动动画),在您的代码中,您可以更改 Animator 的“isIdle”参数,移动时将其设置为 false,停止移动时将其设置为 true。总的来说,我强烈建议您观看一些有关 Unity 中的最终状态机动画的教程,以便您更好地理解这一切。