Door is glitching open and close

Needing a door to open and close, I hunted for a tutorial as to how it is done. I came across this video: How to Make a Door Open and Close in Unity3D - YouTube, and started on my door. At first, the door would just open when the gameplay started, but the code initially had a void start so I changed it to void update. It fixed the door opening on its own problem, but when I get close to the door and stand in the door frame, the door will glitch open and close (it is supposed to stay open when the character is in the box collider, and then close when the character is not in it). Here is the code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DoorScript : MonoBehaviour {

Animator anim;

// Use this for initialization
void Update () {
    anim = GetComponent<Animator>();
}

void OnTriggerEnter(Collider other)
{
    anim.SetTrigger("OpenDoor");
}

void OnTriggerExit(Collider other)
{
    anim.enabled = true;
}

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

This is almost the exact code from the video (except for the first method) and it worked for the guy in the tutorial (my friend thinks that I need another animation for CloseDoor as well as OpenDoor, yet they are the same thing and the animation is supposed to pause at the animation event until the character exits the collider). Let me know if you need any more information that would help you with figuring out the solution.

EDIT: @highpockets It is still glitching out. I copied the code that you sent, it does not open right on pressing play, so that is good, but it isn’t closing when I go through the door. It is staying open. Here is a picture of the door open when it should not be: Notion – The all-in-one workspace for your notes, tasks, wikis, and databases.. Also, you said that “if it keeps opening and closing after you go on the trigger and leave the first time, it is likely because it is the default state in your animator layer” but here is an image of my animation: Notion – The all-in-one workspace for your notes, tasks, wikis, and databases., so that is not an issue, since the default layer is on “DoNothing” and not on “DoorAnimation”.

I think it should look like my code below. You have a method called pauseAnimationEvent() that isn’t being called in the script, but I think you should have an open door and close door animation and do what I have done. You can quite easily turn the animation clip into an additional one that is a reversed of the original by adding a second of the same clip in the import settings and then put it in your animator and click on the state and tick mirror. And setting the animator in the Start method is the right call because otherwise you are just setting the variable to the same thing every frame.

    using System.Collections;
     using System.Collections.Generic;
     using UnityEngine;
    
     public class DoorScript : MonoBehaviour {
    
     Animator anim;
     // Use this for initialization
     void Start () {
         anim = GetComponent<Animator>();
     anim.enabled = false;
     }
     void OnTriggerEnter(Collider other)
     {
         anim.SetTrigger("OpenDoor");
     }
     void OnTriggerExit(Collider other)
     {
         anim.enabled = true;
     }
public void pauseAnimationEvent()
 {
     anim.enabled = false;
 }