BUZZE BUZZE - 1 year ago 65
C# Question

I can't hide my object in the UI

For some reason when I try to call

renderer.enabled = false;

on a label contained in the UI, I get no warning but nothing happens.

I also tried to use SetActive or change the active property directly but unity doesn't recognize it, it will not autocomplete, and will show an error there.

Any suggestion ?

Answer Source

You can use GetComponent<Renderer>().enabled = false; to disable the GameObject's Renderer component. This will mean the Renderer simply does not render the GameObject. Unity docs for Renderer.enabled here.

Alternatively, if you want to make the UI element invisible you could add a Canvas Group component to it and set the Alpha channel to 0. This makes the element (and any of its children) 100% transparent.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download