C# Unity 3D滚动动画中途停止

C# Unity 3D滚动动画中途停止,c#,unity3d,C#,Unity3d,所以我是几天前开始的unity新手,也是c 我有一个问题,动画没有播放到最后,它只是在中间剪辑这里是youtube链接,所以你可以查看它 这是我自己为动画制作的代码 public class PlayerControllerAnimations : MonoBehaviour { public Animator anim; void Start () { anim = GetComponent<Animator>(); } void Update() { //i

所以我是几天前开始的unity新手,也是c 我有一个问题,动画没有播放到最后,它只是在中间剪辑这里是youtube链接,所以你可以查看它

这是我自己为动画制作的代码

public class PlayerControllerAnimations : MonoBehaviour
{
public Animator anim;

void Start ()
{
    anim = GetComponent<Animator>();
}

void Update()
{

    //if(Input.GetAxis("Horizontal") != 0) 
    if (Input.GetAxis("Horizontal") !=0)
    {
        anim.SetBool("isWalking", true);
    }
    else if (Input.GetAxis("Vertical") != 0)
    {
        anim.SetBool("isWalking", true);
    }else
    {
        anim.SetBool("isWalking", false);
    }

    if (Input.GetKey(KeyCode.LeftShift))
    {
        anim.SetBool("isSprinting", true);
    }else
    {
        anim.SetBool("isSprinting", false);
    }
     //if (Input.GetKey(KeyCode.V))
    if (Input.GetButtonDown("Roll"))
    {
        
        anim.SetBool("isRolling", true);
    }
    else
    {
        anim.SetBool("isRolling", false);
    }
    if (Input.GetButtonDown("Roll") && anim)
    {
        anim.StopPlayback();
        //Stop(GetComponent<Animator>());
    }
 }
}
这个代码我只是从网上复制粘贴

private Health Hp;
private Rigidbody Rb;

private Animator Anim;

public float DelayBeforeInvisible = 0.2f;
public float InvisibleDuration = 0.5f;

public float DodgeCoolDown = 1;
private float ActCooldown;

public float PushAmt = 3;

void Start()
{
    Hp = GetComponent<Health>();
    Rb = GetComponent<Rigidbody>();
    Anim = GetComponentInChildren<Animator>();
}
void Update()
{
    bool Roll = Input.GetButtonDown("Roll");
    if (ActCooldown <= 0)
    {
        Anim.ResetTrigger("Roll");
        if (Roll)
        {
            Dodge();
        }
    }
    else
    {
        ActCooldown -= Time.deltaTime;
    }
    void Dodge()
    {
        ActCooldown = DodgeCoolDown;
        Hp.Invisible(DelayBeforeInvisible, InvisibleDuration);

        Rb.AddForce(transform.forward * PushAmt, ForceMode.Force);

        Anim.SetTrigger("Roll");
    }
  }
}

可能是因为您的滚动动画退出状态在代码中设置为isRolling=false,它会显示if Input.GetButtonDownRoll-else,这意味着您放开键的那一刻,isRolling=false。如果这是一个问题,您可以通过勾选动画转换中的Has exit time框来解决它。或者,您可以创建一个计时器浮动,以便在特定时间内将isRolling恢复为false。

Unity动画树中可能存在问题,请检查过渡是否按预期工作。