I am new to NGUI
and unity 3d
.
I have two panels in a ui
root. its named as firstPanel
and secondPanel
. secondPanel is deactivated in scene. In firstPanel
i have so many buttons and one is a play
button, that is image button. While Clicking on play
button, firstPanel
should get hide and secondPanel
should show.I adde a new Script to play
button and written code in it
void OnClick(){
GameObject panel2 = GameObject.Find("secondPanel");
NGUITools.SetActive(panel2,true);
GameObject panel1 = GameObject.Find("firstPanel");
NGUITools.SetActive(panel1,false);
}
But I get this Error : "NullReferenceException"
In which script of ngui
i have to edit and how can i do it? please help me to solve this issue
Thanks in advance.
If your panels are named as Panel1 and Panel2, you will not find them by using GameObject.Find("secondPanel") and GameObject.Find("firstPanel"). If "Panel1" and "Panel2" is the only name in the game scene(No other Panel1 or Panel2), then you can try to use
void OnClick(){
GameObject panel2 = GameObject.Find("Panel2");
NGUITools.SetActive(panel2,true);
GameObject panel1 = GameObject.Find("Panel1");
NGUITools.SetActive(panel1,false);
}