My player Robot
is attacking when I click on the attack button as follows. I am using a coroutine
to wait for some time then instantiate laser form firepos
position.
Please see the below gif
for clear understanding:
Now if u see the above gif
you can see that if I press and hold the attack button the player is doing his animation and according to waitForSeconds
coroutine
after one sec the laser shoots. Its fine till now !
But when I suddenly tap on button many times within a small time the animation doesn't plays(which I can understand..its obvious!) but just like the above case after some time(due to waitforseconds
) and due to no of times I tapped the same no of lasers shoot which I DO NOT WANT !
what I want is that when I click and hold the attack button the animation should complete and then the laser should shoot .
AND
If I tap it many times within a small time the laser(which is a prefab getting instantiated ) should not shoot.
The laser should shoot only when animation gets completed.
Now I am not able to figure that out ! Can any body help.
for button (attack ) in inspector :
I am calling two functions in OnpointerDown
and up
functions code:
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;
}
and Coroutine code(there are two for left and right):
IEnumerator DelayMethodLeftInstantiate(){
yield return new WaitForSeconds(1);
Instantiate (leftLaser, firep.position, Quaternion.identity);
}
IEnumerator DelayMethodRightInstantiate(){
yield return new WaitForSeconds(1);
Instantiate (RightLaser, firep.position, Quaternion.identity);
}
Please help and sorry for lack of knowledge ...Guys Im noob !