使用双向动画时的回退问题

Fallback problem when using bidirectional animation

我有一个使用双向动画的层(层名称是“Base Layer”)

screenshot of the layer

要使 2 工作,1 必须完成 运行。我应该如何添加到下面的源代码中?

(1方向由一个变量触发,当我用鼠标右键单击时该变量为真)

//the function is called inside the update method
private void PunchAnim()
        {
            if (_hasAnimator)
            {
                if (_input.punch)
                {
                    _animator.SetBool(_animIDPunch, true);
                }
            }
        }

我试过了,但没用

private void PunchAnim()
        {
            if (_hasAnimator)
            {
                if (_input.punch)
                {
                    _animator.SetBool(_animIDPunch, true);
                    int baseLayerIndex =_animator.GetLayerIndex("Base Layer");
                    if (_animator.GetCurrentAnimatorStateInfo(baseLayerIndex).IsName("Punch") && _animator.GetCurrentAnimatorStateInfo(baseLayerIndex).normalizedTime < 1.0f)
                    {
                     //still working
                    }
                       
                    else
                    {
                       _animator.SetBool(_animIDPunch, false);
                    }
                
            }
        }

问题已通过以下代码解决

private void PunchAnim()
        {
            if (_hasAnimator)
            {
                if (_input.punch)
                {
                    _animator.SetBool(_animIDPunch, true);
                }

                int baseLayerIndex = _animator.GetLayerIndex("Base Layer");
                if (_animator.GetCurrentAnimatorStateInfo(baseLayerIndex).IsName("Punch") && (_animator.GetCurrentAnimatorStateInfo(baseLayerIndex).normalizedTime > _animator.GetCurrentAnimatorStateInfo(baseLayerIndex).length))
                {
                    _animator.SetBool(_animIDPunch, false);
                    _input.punch = false;
                }
            }
        }