Unity 2D - 跳跃动画重置

Unity 2D - Jump Animation Reset

我是 Unity 世界 (2D) 的新手,我 运行 遇到了一些问题。

我有一个要跳转的脚本。当我跳跃时,跳跃动画非常快。你只能在动画师中看到它。

我有两个其他动画(空闲,运行)可以正常工作。

你能帮帮我吗? :(

    public class Player : MonoBehaviour

{
    private Rigidbody2D rigid;

    [SerializeField]
    private float jumpForce = 5.0f;
    private bool resetJump;
    [SerializeField]
    private float speed = 5.0f;
    private PlayerAnimation playerAnim;
    private SpriteRenderer playerSprite;

    // Start is called before the first frame update
    void Start()
    {
        ...
    }

    // Update is called once per frame
    void Update()
    {
        Movement();
    }

    void Movement()
    {
        float move = Input.GetAxisRaw("Horizontal");
        Flip(move);

        if (IsGrounded())
        {            
            playerAnim.Jump(false);
        }

        if (Input.GetKeyDown(KeyCode.Space) && IsGrounded() == true)
        {
            rigid.velocity = new Vector2(rigid.velocity.x, jumpForce);            
            StartCoroutine(ResetJumpNeededRoutine());
            playerAnim.Jump(true);
        }        
        rigid.velocity = new Vector2(move * speed, rigid.velocity.y);
        playerAnim.Move(move);
    }

    void Flip(float move)
    {
        ...
    }

    bool IsGrounded()
    {
        RaycastHit2D hitInfo = Physics2D.Raycast(transform.position, Vector2.down, 0.3f, 1 << 8);
        if (hitInfo.collider != null)
        {
            if (resetJump == false)
            {
                return true;
            }
        }
        return false;
    }

    IEnumerator ResetJumpNeededRoutine()
    {
        yield return new WaitForSeconds(0.1f);
        resetJump = false;
    }
}

问题出在你的代码中,就在按下 space 之后,resetjump 变得错误并且 isGrounded() 返回 true,因此跳跃动画变得错误。所以我坚持要设置触发器而不是设置 playerAnim.jump 使用 playerAnim.SetTrigger("Jump").

关于动画触发器的研究我们使用触发器来播放像射击和跳跃这样的动画,因为这些动画是真实的,然后在下一个瞬间是假的。