Hi, my character has got 2 hiting animations. When the player presses the attack button, play the first attack animation. When he presses a second time the attack button while the first animation is playing, play the second one.
I have put a if statement in another. Maybe a boolean " isPlaying " is possible. What do you think ?
Thank you.
Edit: Found a better way. I don’t know if this is the best solution, but it works i think. Not tested though.
var firstHit : boolean = true; // So the button is not pressed several times.
var responseTime : float = 0.3F; // response time, so you don't doublehit even you don't hit twice
var TimeOfDoubleHit : float = 2F; // For how long can you wait before hitting the button for the second time.
var counter : int = 0;
var hits = new Array ("hit1","hit2","hit3");
function Update () {
if(Input.GetKey(KeyCode.A)) {
if (firstHit && counter < 3) {
firstHit = false;
animation.Play (hits[counter]);
if (counter == 0) {
StartTimer();
}
ResponseTime();
counter++;
}
}
}
function ResponseTime() {
yield WaitForSeconds(responseTime);
firstHit = true;
}
function StartTimer() {
yield WaitForSeconds(TimeOfDoubleHit);
counter = 0;
}