- Home /
Mecanim combo system occasionally stops and registers phantom clicks
Hello everyone, first post ever so feel free to direct me to the relevant sections or point out other flaws in my post.
I'm trying to get a simple 2d project to work, specifically the combo system. I'm using C#. The combo system I'd like to have would be one that at the first click of the mouse plays the first attack animation, then checks if other clicks were made and if they are more than 2 plays the second attack animation (otherwise goes back to idle), it then does the same with the third attack animation.
I set this up with mecanim and animation events and it mostly works if not for two things that happen quite often: 1 - when clicking the mouse only two times all three attack animations will play (it doesn't happen every time); 2 - when rapidly clicking the mouse a point will eventually be reached in which no more animations are played. This last error I get really baffles me, I cannot for the love of myself understand what could be causing it, no messages or warnings are displayed.
Below you can find the code I'm using, my animator window and the transitions details. I'd really appreciate any help or insight as I'm pretty new to mecanim and animations in general.
START OF CODE
void Start() { clickNumber = 0; canAttack = true; myAnimator = GetComponent(); }
void FixedUpdate()
{
if (Input.GetMouseButtonDown(0))
{
ComboStart();
}
}
void ComboStart()
{
if (canAttack == true)
{
clickNumber++;
}
if(clickNumber == 1)
{
myAnimator.SetInteger("Attack", 1);
}
GameObject.Find("Look").GetComponent<LookAtMouse>().canRotate = false;
}
//this gets called near the end of the attack animations
void ComboCheck()
{
canAttack = false;
if (myAnimator.GetCurrentAnimatorStateInfo(1).IsName("Glove_Attack1") && clickNumber == 1)//if the first anim is playing and we only clicked 1 time
{ //return to idle
myAnimator.SetInteger("Attack", 0);
canAttack = true;
clickNumber = 0;
GameObject.Find("Look").GetComponent<LookAtMouse>().canRotate = true;
}
else if (myAnimator.GetCurrentAnimatorStateInfo(1).IsName("Glove_Attack1") && clickNumber >= 2)//if the first anim is still playing and at least 2 clicks were made
{ //continue combo
myAnimator.SetInteger("Attack", 2);
canAttack = true;
}
else if (myAnimator.GetCurrentAnimatorStateInfo(1).IsName("Glove_Attack2") && clickNumber == 2)//if the second anim is still playing and only 2 clicks were made
{ //return to idle
myAnimator.SetInteger("Attack", 0);
canAttack = true;
clickNumber = 0;
GameObject.Find("Look").GetComponent<LookAtMouse>().canRotate = true;
}
else if (myAnimator.GetCurrentAnimatorStateInfo(1).IsName("Glove_Attack2") && clickNumber >= 3)//if the third anim is still playing and at least 3 clicks were made
{ //continue combo
myAnimator.SetInteger("Attack", 3);
canAttack = true;
}
else if (myAnimator.GetCurrentAnimatorStateInfo(1).IsName("Glove_Attack3"))//if the last anim is playing
{ //return to idle
myAnimator.SetInteger("Attack", 0);
canAttack = true;
clickNumber = 0;
GameObject.Find("Look").GetComponent<LookAtMouse>().canRotate = true;
}
else
{
myAnimator.SetInteger("Attack", 0);
canAttack = true;
clickNumber = 0;
GameObject.Find("Look").GetComponent<LookAtMouse>().canRotate = true;
}
}
My animator window
Transitions details from idle to attack1. All the other transitions are exactly like this one except for the condition that becomes "Equals 2" for Attack1 to Attack2, "Equals 3" for Attack2 to Attack3 and "Equals 0" for going back to idle from any attack.
The (blue) animation event calls ComboCheck() (code above), I set up an animation event that calls the method in all of the attack animations. https://gyazo.com/bbbf530d7914914e9a2712472d463149
Thanks to anyone that offers any help, feel free to tell me any best practices I'm not following regarding mecanim or anything at all and if you need more details in order to understand the problem please tell me and I'll provide them.
[3]: https://gyazo.com/bbbf530d7914914e9a2712472d463149
Your answer
![](https://koobas.hobune.stream/wayback/20220612185656im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
What is the proper way to wait for an Animator Controller to update? 1 Answer
Issue with mecanim playing an animation using setbool 1 Answer
How to use mecanim to play specific animation clips when public static int condition is reached? 2 Answers
Mecanim: get animation duration from Animator state name 0 Answers