Son*_*ona 6 c# monodevelop unity-game-engine ngui
我是新来的NGUI和unity 3d.我在ui根中有两个面板.它的名字firstPanel和secondPanel.secondPanel在场景中停用.在firstPanel我有这么多按钮,一个是play按钮,即图像按钮.当点击play按钮,firstPanel应该得到隐藏,并secondPanel应表现.我阿迪新的脚本play按钮,并编写的代码在它
void OnClick(){
GameObject panel2 = GameObject.Find("secondPanel");
NGUITools.SetActive(panel2,true);
GameObject panel1 = GameObject.Find("firstPanel");
NGUITools.SetActive(panel1,false);
}
Run Code Online (Sandbox Code Playgroud)
但我得到这个错误:我必须编辑"NullReferenceException"
哪个脚本,ngui我该怎么办呢?请帮我解决这个问题在此先感谢.
如果您的面板命名为Panel1和Panel2,则使用GameObject.Find("secondPanel")和GameObject.Find("firstPanel")找不到它们.如果"Panel1"和"Panel2"是游戏场景中唯一的名称(没有其他Panel1或Panel2),那么您可以尝试使用
void OnClick(){
GameObject panel2 = GameObject.Find("Panel2");
NGUITools.SetActive(panel2,true);
GameObject panel1 = GameObject.Find("Panel1");
NGUITools.SetActive(panel1,false);
}
Run Code Online (Sandbox Code Playgroud)