Attack Animation locks up when clicking a second time during the animation

Alright so… this is really annoying me and I have no idea how I would fix such a thing so I really really need help.

So I’m messing around with animations in unity, and I was able to find out how to make a combo system (click 3 times for 3 different attack animations). The problem, though, is when I click during an animation through a small window… it locks up the animation. Not only does it lock it up there, but it locks up the final animation if I spam click (a lot of people spam click with hack n’ slash type games)

Here is the code that I used for the attack animations.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Combat : MonoBehaviour {
    

    public Animator anim;

    private int noOfClicks;
    private bool canClick;

	// Use this for initialization
	void Start () {
        noOfClicks = 0;
        canClick = true;
	}
	
	// Update is called once per frame
	void Update () {
        if (Input.GetMouseButtonDown(0))
        {
            ComboStarter();
        }
	}

    void ComboStarter()
    {
        Debug.Log("Combo Starter");

        if (canClick)
        {
            noOfClicks++;
        }

        if (noOfClicks == 1)
        {
            anim.SetInteger("Animation", 1);
        }
    }

    public void ComboCheck()
    {

        canClick = false;

        if (anim.GetCurrentAnimatorStateInfo(0).IsName("Attack 1") && noOfClicks == 1)
        {
            anim.SetInteger("Animation", 0);
            canClick = true;
            noOfClicks = 0;
            //move.Attacking = false;
        }
        else if (anim.GetCurrentAnimatorStateInfo(0).IsName("Attack 1") && noOfClicks >= 2)
        {
            anim.SetInteger("Animation", 2);
            canClick = true;
            //move.Attacking = false;
        }
        else if (anim.GetCurrentAnimatorStateInfo(0).IsName("Attack 2") && noOfClicks == 2)
        {
            anim.SetInteger("Animation", 0);
            canClick = true;
            noOfClicks = 0;
            //move.Attacking = false;
        }
        else if (anim.GetCurrentAnimatorStateInfo(0).IsName("Attack 2") && noOfClicks >= 3)
        {
            anim.SetInteger("Animation", 3);
            canClick = true;
            //move.Attacking = false;
        }
        else if (anim.GetCurrentAnimatorStateInfo(0).IsName("Attack 3"))
        {
            anim.SetInteger("Animation", 0);
            canClick = true;
            noOfClicks = 0;
            //move.Attacking = false;
        }

    }
}

(I used this code off of a video that really helped)

The ComboCheck() function is called whenever a certain part of the animation plays. Typically around where they transition is where it is called (using the event system)

121350-image.png

The above image shows a general transition of one of the attacks (that can lock up) … my thought is that the problem lies where I placed the event as when I place it somewhere else it locks up differently.

I’d really like some help on this matter… thank you!

If there is anything you need to know, I can provide as much more information as you may need (it’s just annoying looking this up and not finding a solution anywhere)

I believe the issue would be with the transitions.


That diagonal blend from Attack 1 to Attack 2 probably needs to complete before another transition can take place. You can change this by clicking on the transition in the Animator view, looking at it in the Inspector view, expanding “Settings” and adding Interruption Source to Next State. This way the Next State should be able to interrupt the animation you clicked on. All of your transitions related to combos should need this change if it solves your problem for the one.

I don’t know anything at all as to why this may occur… some insight would be nice…

why are you using integers and what are the conditions for the transition between attack 1 and attack 2?
I feel it might lock up because the conditions are not met.