How do I toggle a checkbox in Unity with code?

匿名 (未验证) 提交于 2019-12-03 02:38:01

问题:

I looked at the Toggle API and can't find a way to set it to checked with code. http://docs.unity3d.com/ScriptReference/UI.Toggle.html

The reason I want to do it is that I want to set a checkbox as checked depending on a setting when the game starts.

Any ideas on how to do this?

Thanks!

回答1:

http://docs.unity3d.com/ScriptReference/UI.Toggle-isOn.html

Use the public variable Toggle.isOn. Set it to true like this: myToggle.isOn = true;.

You probably looked for a method, but don't forget to also look at the public variables, as these are part of the API as well.



回答2:

Toggle.isOn wont do anything, sorry. do this:

toggle.onValueChange.Invoke(true) //or false if you want to uncheck it 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!