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 ?
You can use GetComponent<Renderer>().enabled = false;
to disable a GameObject's Renderer component. This will mean the Renderer simply does not render the GameObject. Unity docs for Renderer.enabled
here .
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.
There is no rendrer attcahed to UI Component so it will always give you error , if you want to hide it or show it .. access it as gameobject using label.gameobject.SetActive(true/false).
Hope it helps
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.