how to disable animator component?

hi! so uh i wanna ask, how do you disable the animator component through script and enable it with UI button click? for like transitions and other stuff

Animator animator;

void Start()
{
    animator.enabled = false; // disables the component
}

public void EnableAnimator()
{
        animator.enabled = true; // enables the component
}

Call this function from the button component in the hierarchy.