【问题标题】:Unity 3D rolling animation stops mid wayUnity 3D 滚动动画中途停止
【发布时间】:2020-08-24 21:59:29
【问题描述】:

所以我是几天前开始接触统一的,并且是 c# 的新手 我有一个问题是动画没有播放到最后它只是在中间切开这里是 youtube 链接所以你可以查看https://www.youtube.com/watch?v=wz5TWh7dTqY

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

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");
    }
  }
}

【问题讨论】:

  • 您的 Unity 动画树可能有问题,请检查转换是否按预期工作。

标签: c# unity3d


【解决方案1】:

可能是因为您的滚动动画退出状态设置为isRolling = false 在您的代码中它显示为if (Input.GetButtonDown("Roll")) else,这意味着您松开键的那一刻,isRolling = false。如果这是问题,您可以通过在动画转换中勾选“有退出时间”框来解决它。或者您可以创建一个计时器浮点数以在特定时间将 isRolling 恢复为 false。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2011-12-03
    • 1970-01-01
    • 1970-01-01
    • 2011-09-16
    • 2021-01-17
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    相关资源
    最近更新 更多