【问题标题】:Fallback problem when using bidirectional animation使用双向动画时的后备问题
【发布时间】:2021-07-28 01:28:12
【问题描述】:

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

screenshot of the layer

要让 2 工作,1 必须完成运行。下面的源码应该怎么添加?

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

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

【问题讨论】:

    标签: c# unity3d animator


    【解决方案1】:

    以下代码解决了问题

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-31
      • 1970-01-01
      • 2021-12-25
      • 1970-01-01
      相关资源
      最近更新 更多