Search Unity

Question Animation runs again even if hitbox is off when the animation runs

Discussion in 'Animation' started by EndrerDeg, Apr 14, 2023.

  1. EndrerDeg

    EndrerDeg

    Joined:
    Dec 9, 2021
    Posts:
    3
    I have made a fighting game in Unity that uses hitboxes so that the character reacts when another character attacks.

    I have a problem when a character1 kicks character2 character1 will run an animation where he falls back. I have made a script where the character1 hitbox turns off when the animation runs.

    if(Player1Layer0.IsTag("Stunned"))
    {
    RB.isKinematic = true;
    BoxCollider.enabled = false;
    CapsuleCollider.enabled = false;
    }
    else
    {
    BoxCollider.enabled = true;
    CapsuleCollider.enabled = true;
    RB.isKinematic = false;
    }

    However, when character2 kicks character1 while his "Stunned" animation runs, he will run the "Stunned" animation again after finishing his previous "Stunned" animation.

    How can I fix this issue?