Check animation has finished

i want to make a fighting game 2d in unity. The problem is when i make animation to punch or kick, it’s always back to idle although it’s still playing. i have tried to use fighter.GetCurrentAnimatorStateInfo(0).IsName(“High Kick”) but still wrong…Anyway this my code:

if (!mulai || berdiri) {
    fighter.SetInteger("gerak", 0);
}

if (Input.GetKey(KeyCode.RightArrow)) {
    fighter.SetInteger("gerak", 2);
    berdiri = false;
}
else {
    berdiri = true;
}
if (Input.GetKeyUp(KeyCode.J)) {
    berdiri = false;
    fighter.SetInteger("gerak", 4);
}
if (Input.GetKeyUp(KeyCode.I)) {
    berdiri = false;
    fighter.SetInteger("gerak", 5);
}
if (Input.GetKeyUp(KeyCode.L)) {
    berdiri = false;
    fighter.SetInteger("gerak", 6);
}
if (Input.GetKeyUp(KeyCode.K)) {
    berdiri = false;
    fighter.SetInteger("gerak", 7);
}

if (fighter.GetCurrentAnimatorStateInfo(0).IsName("Low Kick")) {
    mulai = true;
    Debug.Log("Low");
    // Avoid any reload.
}
else if (fighter.GetCurrentAnimatorStateInfo(0).IsName("High Kick")) {
    mulai = true;
    Debug.Log("High");
    // Avoid any reload.
}
else if (mulai) {
    mulai = false;
}

Sorry for my lack of english… I hope someone can help me. Thanks

You need to have something like a state machine, which knows which attack / move is currently active and then decides, if the player can perform a kick while still doing another attack.

To prevent from going back to idle, you need to make sure your variables are correctly set (right kick is true at the end of left kick) and also you need to add a transition from left to right kick - just go back to idle if right kick is false, for example.

AnimationStates own a property named “normalizedTime” which tells you the state and play times of the current animation - for example, 3.25f tells you, that the animation was played three times and currently resides at 25% of the animation clip.
AnimationState % 1.0f will result in only having the playback position.