- Home /
Question by
VINNUSAURUS · Jul 05, 2018 at 09:43 AM ·
scripting problemscript.user interfacetoggle buttonbegginer
How to access a Toggle or any User Interface object from script properly.
public void RandomMethod()
{
//randomPanel is the 7th child inside UICanvas.
Transform randomPanel = GameObject.Find("UICanvas").transform.GetChild(7);
//toggleButton is a Toggle and the first child of randomPanel
Transform toggleButton = randomPanel.gameObject.transform.GetChild(1);
}
How to convert the toggleButton transform to Toggle gameobject ?
Comment
Via the gameObject property
Transform mTransform;
GameObject gameObjectOfmTransform = mTransform.gameObject;
Best Answer
Answer by VINNUSAURUS · Jul 05, 2018 at 10:57 AM
Sorry for the trouble found the answer
public void RandomMethod()
{
//randomPanel is the 7th child inside UICanvas.
Transform randomPanel = GameObject.Find("UICanvas").transform.GetChild(7);
//toggleButton is a Toggle and the first child of randomPanel
Transform toggleButton = randomPanel.gameObject.transform.GetChild(1);
Toggle t = randomPanel.gameObject.transform.GetChild(1).gameObject.GetComponent<Toggle>();
}
Your answer
![](https://koobas.hobune.stream/wayback/20220612170059im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Ui follow player fixed position 0 Answers
Slowly increase motor.force 1 Answer
How can i make objects to move in random speed ? 1 Answer
Sorting a list based of a variable 1 Answer