- Home /
ugui C# coding, get checkbox status and set highlighted button
OK, I give up, after a-lot of wasted time on 4.6 ugui, i haven't been able to work it out, my 2 questions are simple
1) how do i get the bool checkbox status for ugui (New Gui system in 4.6)
I expected something like :
gameObject.transform.FindChild ("MyCheckbox").GetComponentInChildren().status
I need this because I don't want the interaction of the checkbox to change anything until an apply button is pressed
2) How do I highlight the first button programatically?
I explicated something like this :
gameObject.transform.FindChild ("MyButton").SetHighlighted().
Again, I have a number of panels, when I turn a panel on I want to set the highlight to the default option so the user can then continue and use keyboard/joystiq to choose an option
Answer by AyAMrau · Sep 02, 2014 at 02:18 PM
1) you can check the status of a toggle (check box) by accessing the Toggle component and it's isOn property:
(requires using UnityEngine.UI;)
bool result = gameObject.GetComponent<Toggle>().isOn;
2) To highlight a button you need to set it as selected on the EventSystem:
(requires using UnityEngine.EventSystems; using UnityEngine.UI;)
// assuming Button selectButton pointing to the button you want to select
EventSystem eventSystem = GameObject.Find("EventSystem").GetComponent<EventSystem>();
eventSystem.SetSelectedGameObject(selectButton.gameObject, new BaseEventData(eventSystem));
Wow! Thank you! You really saved my ass - now controller works with my project. :) Couldn't found this anywhere else. Thanks again!
Your answer
![](https://koobas.hobune.stream/wayback/20220613162128im_/https://answers.unity.com/themes/thub/images/avi.jpg)