What is the checkbox in the Unity Inspector Tab Called?

image

The checkbox on the left of the Game Object name (Player Rig) and the right of the cube is for showing and hiding the gameObject. I want to be able to enable and disable that checkbox (NOT the MeshRenderer!)

I suppose it is something like

GetComponent<Checkbox>().enabled = false;

How do you enable/disable that checkbox?

Hi,

You cannot make any GUI elements in the Inspector invisible. If you want to disable the game object, call SetActive(false); in a script attached to the game object.


See also:

So this is my code;

    bool debugMenuActive = false;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F2))
        {
            if (debugMenuActive == false)
            {
                gameObject.SetActive(false);
            }
            if (debugMenuActive == true)
            {
                gameObject.SetActive(true);
            }
            debugMenuActive = !debugMenuActive;
        }
    }

It is able to turn of the gameObject, but not turn it back on.

Is this script running on the same game object that is supposed to get disabled? If so, that might be the reason why you cannot activate the game object again. Update() gets called only on active components (and game objects). Assign your script to a game object that is always enabled and connect the other game object whose state is supposed to get toggled with it. Do you know the [SerializeField] attribute? If not, look it up in the API.

Okay, I will try it! Thanks!

It is working, thank you!

    [SerializeField] GameObject debugPanel;
    bool debugMenuActive = false;

    void Update()
    {
        if (Input.GetKeyDown(KeyCode.F2))
        {
            if (debugMenuActive == false)
            {
                debugPanel.SetActive(true);
            }
            if (debugMenuActive == true)
            {
                debugPanel.SetActive(false);
            }
            debugMenuActive = !debugMenuActive;
        }
    }

Good job! :slight_smile:

Thank you!

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms