Disable collider at end of animator

I have a Player object with a child object called AttackArea. When the player attacks two things happen:

  1. The Animator object parameter IsAttacking is enabled and the animator begins the attacking animation.
  2. The AttackArea is enabled

My goal is to disable the AttackArea when the Animator is finished with the attack animator animation. I haven’t found any code specific to the animator. Everything references the Animation component. Is it possible to get the status of the Animator component in code?

If I understand your requests correctly, I think you could just set the AttackArea enabled and disabled directly in your animation. Just select your Player object, open Window > Animation and via the “Add Property” button, you navigate to your AttackArea-Element and press the little (+) next “IsActive”. Now you can add KeyFrames for the IsActive-Property as you like - enable it at the beginning and disable at the end of the animation.

Not that I see from the class reference, but if you know how long the animation is, you could have a coroutine or Invoke() start at the same time as IsAttacking and wait for the same duration as the animation, then disable the AttackArea.

As a coroutine, it’d look like this

private IEnumerator DisableAttackArea(float animationLength)
{
    while(animationLength > 0)
        yield return null;
    AttackArea.SetActive(false);
    yield break;
}

void OnAttack()
{
    AttackArea.SetActive(true);
    // Start the animation here
    StartCoroutine("DisableAttackArea", lengthOfAnimation);
}

Or, if you want to do it as Invoke(),

void DisableAttackArea()
{
    AttackArea.SetActive(false);
}

void OnAttack()
{
    AttackArea.SetActive(true);
    // Start the animation here
    Invoke("DisableAttackArea", lengthOfAnimation);
}