I have been researching a lot on attack animations and scripting combos. I have used the following code that I’ve found online but I had a few questions about it, if anyone has to time to clarify.
Code Sample:
if (Input.GetButtonDown("Punch") && isGrabbing == false)
{
LastPress = Time.timeSinceLevelLoad;
if(tap > 2)
{
tap = 1;
}
else
{
tap++;
}
Combo2();
}
if(timer - LastPress > 1)
{
tap = 0;
if(timer - LastPress < Atime)
{
attack = false;
}
else
{
attack = true;
}
}
I do not fully understand how to control the key presses. When I press my Punch button, the animation is constantly interrupted because there is not delay between key press.
The following code is a switch statement that I’m using with Unity’s Animator Control because I’m using Unity2D, which does not allow “legacy animations”
Switch Statement:
void Combo ()
{
//WaitForSeconds(2);
if(attack)
{
switch (tap)
{
case 0:
//Reset to Idle
anim.Play("FightStance");
break;
case 1:
//Combo Start
anim.Play("punch1 1");
break;
case 2:
//Combo Prolonge
anim.Play("punch2");
break;
case 3:
//Combo Finished
anim.Play("kick1");
break;
}
}
}
Sorry for all the detail but my main question is: How can I allow the animator to play my full attack animation before I press the Punch button to perform the next animation. Also, is it possible to force my pressing of the Punch button be inactive until the animator finish playing my animation state.
Thanks in advance to anyone who can help me with this Unity2D puzzle.