Hide/Show my GUI (Inventory) with input


well, it’s a simple game, although I know in Game Maker, here in Unity things are completely different…
I just wanted to know how I could hide this inventory screen when you press J/C, as it seems to be very different from hiding an element/object/sprite

I have a script called inv_visible, which was attached to the gameobject inventory, in Hierarchy, that can controll the visibility of inv

this is the code inside:

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

public class inv_visible : MonoBehaviour
{

    public GameObject pic;

    public void Trigger()
    {

        if (pic.activeInHierarchy == false && Input.GetKeyDown(KeyCode.F))
        {

            pic.SetActive(true);

        }
        else
        {

            pic.SetActive(false);

        }

    }

}

note: Inventory is a Canvas, and it has warnings like this because my laptop is weak.
Sorry for the big text.

You have to use Update function and write your code inside it. The Update function gets called by unity every frame. Check out this page from Unity’s documentation for more info.

Hnm, i see
I will take a look
thanks
(I had forgotten that I had to call the methods, I almost tried to make a C# hook like Rain World)

It worked,
and thanks to one thing I forgot it MUST be called
Thanks, and I adjusted the code too

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

namespace inventorys
{

    public class inv_visible : MonoBehaviour
    {
        [SerializeField]
        public GameObject pic;
        private bool is_enabled = false;

        public void Trigger()
        {

            if (pic.activeInHierarchy == false && Input.GetKeyDown(KeyCode.F))                  //if press F (inventory)
            {

                is_enabled = true;                                                              //enabled

            }
            else if (pic.activeInHierarchy == true && Input.GetKeyDown(KeyCode.F))             //if press F (inventory)
            {

                is_enabled = false;                                                             //disabled

            }

            if (is_enabled == false)                                                             //if disabled
            {

                pic.SetActive(false);                                                           //set to the active = true

            }
            else if (is_enabled == true)                                                         //if enabled
            {

                pic.SetActive(true);                                                            //set to the active = true

            }

        void Update()
        {

            Trigger();                                                                          //trigger the input

        }

    }

}

I’m gald it worked. In order to make your code lceaner you can write your Trigger method like the code below and remove is_enabled.

private void Trigger()
{
    if (Input.GetKeyDown(KeyCode.F)
    {
        pic.SetActive(!pic.activeInHierarchy);
    }
}

Also the comments don’t really do anything or explain more, so you should avoid such comments in your code.

Hmmmmmmm i see
This could be very useful not only in this game, but also in my Rain World mod
Except for the fact that I tend to explain everything with a comment, due to forgetfulness
I can see
Really thank you :)

The warnings have nothing to do with your laptop. The first message is just alerting you that more channels are enabled than may be required, and the second that you’re in one color mode and the canvas is defaulting to the other color mode which may cause incorrect colors.

I see
OOF
I never touched those parts, tbh
like, it came from the factory
Thanks for explaining that too >:)