Why does my UI flicker when i press the button?

Hello, short and sweet: I would like to open and close the inventory in my game using a button.

I want to toggle the “I” key.
My code in the character controller script:

   `if (Input.GetKey(KeyCode.I))
                {
                    bool isActive = Panel.activeSelf;
                    Panel.SetActive(!isActive);
                }`

I created a variable for the panel and linked the variable to my character with the panel.

public GameObjectPanel;

This works quite well so far, my only problem is that it flickers, as if the program couldn’t decide whether the panel is active or inactive. I just uploaded it… and I hope you can help me. Flickering Issue :( - YouTube

greetings from the north

Use Input.GetKeyDown not Input.GetKey. GetKeyDown tracks when the player presses the key and GetKey is when the player holds down the button. It’s flickering because while you are holding down that button its running your code over and over instead of just once when you push it down.