SetBool isn’t working in runtime.

Hey there!
I’ve ran into a problem whilst creating a slide in and slide out animation for a panel in the UI. Basically, I’m trying to get the panel to slide in when the “E” key is pressed and to slide out when it is pressed again. I’ve set up the animator with one bool named “isOpen”.

    bool isOpen = false;

    public Animator phoneAnimator;

    public void Update()
{
if (Input.GetKeyDown("e") && !isOpen)
{
            phoneAnimator.SetBool("IsOpen", true);
            isOpen = true;
}
       
        if (Input.GetKeyDown("e") && isOpen)
{
            phoneAnimator.SetBool("IsOpen", false);
            isOpen = false;
        }
    }

I can upload the animators transitions if that would help too!

Thanks in advance!

Hey,

You actually had me scratching my head for a few minutes haha.

You need to make the second if statement an “else if” instead. The issue is that you set isOpen to true in the first if statement (making the second if statement true), then go to the second if statement on the same frame and immediately set it back to false.