Making an Animation pause function in a different game object

I am working on animating a door in my game. I have a parent game object that hosts the door object. This is because the box collider rotated with the door when it was attached to it, so now, since the collider is on the parent, it will not rotate. But since the script is on the parent calling the animator component from the child, it cannot be used for an animation event. I originally had

private void pauseAnimationEvent(){
anim.enabled = false;
}

This is so it would stop the door at a specified point so that it stayed open until the character went out of the box collider’s area and triggered the door to close. My question is, is there a way to call this function to an animation event that is on the animation of the door which is the child of the object that the script is on? I know it is a weird question, but I would appreciate any help.

The parent object can have a reference to the child script in a script on the parent like so:

public ChildScriptName childScript; //drag the child script into the field in the inspector, has to be the child instance of the script

void Update(){

//Call the function
childScript.pauseAnimationEvent();

}

That should do it.

Cheers

I’m a little confused as to how you have your scene setup. If I understand correctly, you have a trigger collider, with a door as a child. If this is the case, and you want to control the animator in the child, you should be able to do something along the lines of this:

public class DoorAnim : MonoBehaviour
{
    private Animator anim;
    private void Start()
    {
        anim = GetComponentInChildren<Animator>();
    }

    private void pauseAnimationEvent()
    {
        anim.enabled = false;
    }

That should, in theory allow you to control an animator which is on a child of the object holding your script.