【问题标题】:Stopping animation (attack) to loop itself when play播放时停止动画(攻击)以循环播放
【发布时间】:2017-01-22 08:01:40
【问题描述】:

我们知道,当动画播放时,它会循环播放(重播),这对运动动画(步行、跑步、跳跃)很有好处。

但在我的情况下,它会造成如图所示的奇怪效果:

现在,当我单击并按住按钮时,我想要的是 the character should take his arm up and then keep it 不像一次又一次地抓住它,直到我的手指不从按钮上松开。

因为它是一个攻击动画所以我不想要它!

攻击脚本和动画调用如下:

public void LaserAttack(){
        isAttacking = true;
        if (robotLeft == true&&isLaserLeft==false) {

            //Debug.Log (firep.position.x);

            //Instantiate (leftLaser, firep.position*1.29f, Quaternion.identity);

            StartCoroutine( DelayMethodLeftInstantiate());

        } 

        if (robotRight == true&&isLaserLeft==false) {

            StartCoroutine(  DelayMethodRightInstantiate());

            //Instantiate (RightLaser, firep.position, Quaternion.identity);
        }
        anim.SetBool ("isAttack", isAttacking);
        isLaserLeft = true;

    }

    public void LaserAttackEnd(){
        isAttacking = false;

        anim.SetBool ("isAttack", isAttacking);
        isLaserLeft = false;
}

我在触摸按钮中调用攻击动画如下!

现在如何实现呢?

【问题讨论】:

    标签: c# animation unity3d unity5 unity3d-2dtools


    【解决方案1】:

    解决方案是创建一个玩家攻击静止的新动画,并使用coroutine

    因为我们希望在攻击动画之后播放另一个动画,并且当它结束时停止两个动画(攻击) 达到预期的输出。

    在 animator 中查看图片中突出显示的内容:

    在代码中:

    public void LaserAttack(){
            isAttacking = true;
            StartCoroutine (AttackStillCoroutine ());
    
            if (robotLeft == true&&isLaserLeft==false) {
    
                //Debug.Log (firep.position.x);
    
                //Instantiate (leftLaser, firep.position*1.29f, Quaternion.identity);
    
                StartCoroutine( DelayMethodLeftInstantiate());
    
            } 
    
            if (robotRight == true&&isLaserLeft==false) {
    
                StartCoroutine(  DelayMethodRightInstantiate());
    
                //Instantiate (RightLaser, firep.position, Quaternion.identity);
            }
            anim.SetBool ("isAttack", isAttacking);
            isLaserLeft = true;
    
        }
    
        public void LaserAttackEnd(){
            isAttacking = false;
            attackStill = false;
            anim.SetBool ("isAttackStill",attackStill);
            anim.SetBool ("isAttack", isAttacking);
            isLaserLeft = false;
    
        }
    

    协程如下:

     IEnumerator AttackStillCoroutine(){
    
                yield return new WaitForSeconds (1);
                attackStill = true;
                anim.SetBool ("isAttackStill",attackStill);
    
            }
    

    又好又简单...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多