- Home /
different animation same button
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.
function Start () {
animation.Stop();
animation.wrapMode = WrapMode.Loop;
var hit1 = animation["hit1"];
hit1 = WrapMode.Once;
hit1 = 1;
var hit2 = animation["hit2"];
hit2 = WrapMode.Once;
hit2 = 2;
}
function Update () {
if(Input.GetButtonDown("attack")) {
animation.Play ("hit1");
if(Input.GetButtonDown("attack")) {
animation.Play ("hit2");
}
}
}
Answer by bompi88 · Dec 16, 2012 at 03:50 PM
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;
}
Thanks this script works like a charm. But it is extremely complicated. And I would Actually like to add a third animation, you know, for a third attack. So I will try to understand it in order to make it possible. Thank you very much. I'm impressed. Apparently you have 666 karma. And that's funny.
can I have a complete script or a complete project based on that 'same button but multiple animation' script? Please.
Found an easier way of implementing it. I edited my answer. hehe, yeah that actually was funny ;-)
Thanks it works ! Way out of my league, though ^^. The response of the character is a little strange, i'll figure it out. I checked out you're games but none of them were out. When will they BE ?
I went back to school. Will get into them whenever I get some spare time ;)