Door Animation looping bug? (Beginner in Animation)

Good day everyone!

So I made a simple door opening and closing animation by rotating the door on the y axis, and I’m running into a bug.

The animation works with raycast and it opens or closes once the left mouse button is clicked.

I’m using two triggers (Open and Close) for my animations and I’m controlling them in my script.

The door opening animation works perfectly fine, however when I want to close the door, it sort of bugs out and loops 2-3 times before reaching the idle state. And what’s even weirder is that it doesn’t do this every time, but rather once in every 2 clicks. I’m not sure what I’m doing wrong.

PS: Loop Time is unchecked for both animations

Here is my code for the door animation:

public class MyDoorController : MonoBehaviour
{
    private Animator doorAnim;

    private bool doorOpen = false;

    private void Awake()
    {
        doorAnim = gameObject.GetComponent<Animator>();
    }

    public void PlayAnimation()
    {
        if (!doorOpen)
        {
            doorOpen = true;
            Debug.Log("door opening");
            doorAnim.SetTrigger("Open");        
        }
        else
        {
            doorOpen = false;
            doorAnim.SetTrigger("Close");
            
        }
    }
}

Here’s what my animator controller looks like:

The transition Idle → DoorOpen has the Open trigger, and the transition DoorOpen → DoorClose has the Close trigger.

What could I be doing wrong?

Until now I hadn’t done something with a trigger-var. I had used bool-vars. Maybe you try it out this way, too? I would remove the “close” and “open” trigger and just add an bool called “doorOpen”, or something like this. Then the script would be like this:

public class MyDoorController : MonoBehaviour
     {
         private Animator doorAnim;
     
         private bool doorOpen = false;
     
         private void Awake()
         {
             doorAnim = gameObject.GetComponent<Animator>();
         }
     
         public void PlayAnimation()
         {
             doorOpen = !doorOpen;
             Debug.Log("doorOpen = "+doorOpen);
             doorAnim.SetBool("doorOpen", doorOpen);;        
             
         }
     }

I’m not sure if it removes your iusse, but you can give it a try.