简体   繁体   English

我无法在界面中隐藏我的对象

[英]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. 我也尝试使用SetActive或直接更改active属性,但unity不能识别它,它不会自动完成,并且在那里显示错误。

Any suggestion ? 有什么建议吗?

You can use GetComponent<Renderer>().enabled = false; 您可以使用GetComponent<Renderer>().enabled = false; to disable a GameObject's Renderer component. 禁用GameObject的Renderer组件。 This will mean the Renderer simply does not render the GameObject. 这将意味着渲染器根本不渲染游戏对象。 Unity docs for Renderer.enabled here . Renderer.enabled文档在此处 Renderer.enabled

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. 如果要使UI元素不可见,则可以向其添加Canvas Group组件并将Alpha通道设置为0。这使该元素(及其子元素)100%透明。

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). UI组件没有属性,因此如果您要隐藏或显示它,它总是会给您错误,请使用label.gameobject.SetActive(true / false)作为游戏对象进行访问。

Hope it helps 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM