Cant get Animator Controller to work properly

So I have a shelf on a desk that slides in and out. Now when I press E on it, it first doesnt do anything, but on the second press it opens and closes right after.

So here is screenshot of my a-controller:

And here is the code that opens and closes it on button press:

   void OnUse()
        Debug.Log("IT WORKSSS");
        if(anim.GetBool("IsClosed") == true)
            anim.SetBool("IsClosed", false);
            anim.SetBool("IsClosed", true);

To properly handle open/close, you actually need 4 states :
close, opening, open, closing.
You don’t even need the trigger, the boolean value is enough.
You can have a look at this 1, in which I touch on the topic.

Hope this helps.

I’m not sure why you have both two triggers and two bools for it. You could do this with only one trigger.

//Create a trigger called 'toggleShelfState' or something

if (Input.GetKey(keycode.E))

As for setting up the transition - simply set one transition from and to. (Make the default state closed i guesss), uncheck “has exit time”, and ensure they both have the same “toggleShelfState” condition. This should allow you to go back and forth between them no problem.

If you wanted to use a bool condition instead, you could do that.

//create a bool called "ShelfOpen" or something like that

if (Input.GetKey(keycode.E))
        anim.setbool("ShelfOpen", !(anim.getbool("ShelfOpen")));

This will have essentially the same toggling effect - it will set the open state to the opposite of whatever it is when you press the button. Then just set transitions, ensure exit time is disabled, and set the condition for opening it to be ShelfOpen = true, and the condition for it closing is ShelfOpen = false