C# 播放时停止动画(攻击)以循环自身
在unity中,我们知道当动画播放时,它会自动循环(回放),这有利于运动动画(行走、奔跑、跳跃) 但在我的例子中,它会产生一种奇怪的效果,如图所示: 现在,当我点击并按住按钮时,我想要的是C# 播放时停止动画(攻击)以循环自身,c#,animation,unity3d,unity5,unity3d-2dtools,C#,Animation,Unity3d,Unity5,Unity3d 2dtools,在unity中,我们知道当动画播放时,它会自动循环(回放),这有利于运动动画(行走、奔跑、跳跃) 但在我的例子中,它会产生一种奇怪的效果,如图所示: 现在,当我点击并按住按钮时,我想要的是角色应该抬起他的手臂,然后保持它,而不是一次又一次地抓住它,直到我的手指从按钮上松开为止 Bcoz这是一个攻击动画,这就是我不想要它的原因 攻击脚本和动画调用如下所示: public void LaserAttack(){ isAttacking = true; if (rob
角色应该抬起他的手臂,然后保持它,而不是一次又一次地抓住它,直到我的手指从按钮上松开为止
Bcoz这是一个攻击动画,这就是我不想要它的原因
攻击脚本和动画调用如下所示:
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;
}
IEnumerator AttackStillCoroutine(){
yield return new WaitForSeconds (1);
attackStill = true;
anim.SetBool ("isAttackStill",attackStill);
}
我在触摸按钮中调用攻击动画,如下所示!
现在如何实现呢?解决方案是创建一个新的玩家攻击动画,并使用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;
}
合作计划如下:
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;
}
IEnumerator AttackStillCoroutine(){
yield return new WaitForSeconds (1);
attackStill = true;
anim.SetBool ("isAttackStill",attackStill);
}
好简单