gpt4 book ai didi

c# - 面板在 NGUI 中隐藏和显示

转载 作者:太空狗 更新时间:2023-10-29 21:05:19 27 4
gpt4 key购买 nike

我是 NGUIunity 3d 的新手。 我在 ui 根目录中有两个面板。它被命名为 firstPanelsecondPanel。 secondPanel 在场景中被停用。在firstPanel 中,我有很多按钮,其中一个是play 按钮,即图像按钮。当点击 play 按钮时,firstPanel 应该hidesecondPanel 应该show。我向 play 按钮添加了一个新脚本并在其中编写了代码

void OnClick(){
GameObject panel2 = GameObject.Find("secondPanel");
NGUITools.SetActive(panel2,true);
GameObject panel1 = GameObject.Find("firstPanel");
NGUITools.SetActive(panel1,false);

}

但是我得到了这个错误:"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);

}

关于c# - 面板在 NGUI 中隐藏和显示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14744155/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com