- Home /
Combo Attack/Animator issue
I'm attempting to make a combo system for a 2D platformer, however I am facing an issue with the current code I have; I am either unable to get the rest of the combo animations to play when clicking after the first attack, or I am able to get them to play, but for whatever reason each animation will loop about three times through each animation (as opposed to once for each, as desired), or they will stop at the first frame for about three seconds before continuing through each animation.. These occurrences seem to hinge on Time.deltaTime, as well as the transition duration field within the Animator Inspector for each respective event. Here is my code for the attacking/combo system, and images of the animator w/ events:
float timeSinceLastAttack = 0;
private int currentAttack = 0;
float resetAttackTime = 2f;
Animator animator;
void Start()
{
animator = GetComponent<Animator>();
animator.SetInteger("Attacks", 0);
}
void Update()
{
xMove = Input.GetAxisRaw("Horizontal") * runSpeed;
animator.SetFloat("xMove", Mathf.Abs(xMove));
EnableInput = true;
if (Input.GetButtonDown("Fire1"))
{
currentAttack++;
timeSinceLastAttack = 0;
animator.SetInteger("Attacks", (currentAttack % 4));
print(" " + currentAttack);
}
else
{
// Increase timer
timeSinceLastAttack += Time.deltaTime;
animator.SetBool("Idle", true);
// If it's been too long, go back to idle
if (timeSinceLastAttack > resetAttackTime)
{
currentAttack = 0;
animator.SetInteger("Attacks", 0);
}
}
The inspector variables are the same for each attack state machine. I have disabled "Loop Time" for each of the attack animations, however as said each animation will repeat three times instead of one even with Loop Time disabled. Any suggestions/help is appreciated.
Your answer
![](https://koobas.hobune.stream/wayback/20220612205247im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
mecanim blend tree attack combo 2 Answers
How to reset attack animations using time.deltatime 2 Answers
Animator Random Parameter Set 0 Answers
Mix and match animations 0 Answers
Animations Combo 0 Answers