So I’ve been working on an attack script like in lots of games, where if you press the attack button once it plays a swipe animation then goes back into the idle animation. If you double tap the attack button it plays the original swipe animation then a second swipe animation. If you triple tap the attack button it plays a three swipe attack combo. I got it all working but the problem was, was that it allowed you to cancel out animations and go back to just a single swipe or double swipe from the triple swipe attack combo. I added a conditional statement in that when one of the animations played it changed the variable to false so that it couldn’t be canceled by another attack. My problem is, is that now it only lets me do a single swipe animation attack because when building up the taps to three it turns the variable to false at one. What I need it to do is not play any animations till it’s sure wether I want a single swipe, double swipe, or triple swipe attack animation. Help??? Thanks.
var tap : int = 0;
var LastPress : float = 1.0;
var StationaryTime : float;
var Atime : float;
var attack : boolean = true;
function Update () {
StationaryTime = Time.timeSinceLevelLoad;
if(Input.GetKeyDown("f")){
var CurrentTime = Time.timeSinceLevelLoad;
if (CurrentTime - LastPress < 1){
if (tap == 1){
tap = 2;
Debug.Log("tap = " + tap);
}
else if(tap == 2){
tap = 3;
Debug.Log("tap = " + tap);
}
}
else{
tap = 1;
Debug.Log("tap = " + tap);
}
LastPress = Time.timeSinceLevelLoad;
}
//if(CurrentTime - LastPress < 1){
//attack = false;
//}
if(StationaryTime - LastPress > Atime){
attack = true;
tap = 0;
}
if(attack){
switch(tap){
case 0:
animation.CrossFade("Idle");
break;
case 1:
animation.CrossFade("Attack1");
Atime = animation["Attack1"].length;
attack = false;
break;
case 2:
animation.CrossFadeQueued("Attack2", 0.3, QueueMode.CompleteOthers);
Atime = 4.7;
attack = false;
break;
case 3:
animation.CrossFade("AttackCombo");
Atime = animation["AttackCombo"].length;
attack = false;
break;
}
}
}