按钮需要点击两次才能隐藏
问题描述:
我开始学习Unity和C#因为我想制作一款游戏。但由于按钮问题,我被卡在这里。按钮需要点击两次才能隐藏
当我运行下面的代码与Unity时,我得到的标签和“跳过”按钮,因为我想。
但是当我按下按钮时,只有切换出来。标签和按钮不隐藏。那么只有当我第二次点击它时,它们才会隐藏起来。
我该如何解决这个问题,以便通过单击按钮“跳过”隐藏按钮和标签并显示切换。
感谢您查看我的问题。
void OnGUI()
{
if (!textfin)
{
GUI.Label(new Rect(0, 0, Screen.width, Screen.height), text, guiStyle);
if (GUI.Button(new Rect(Screen.width * 4/5, 0, Screen.width/5, Screen.height/5), "SKIP"))
{
textfin = true;
}
}
else{
easy = GUI.Toggle(new Rect(Screen.width/4, 0, Screen.width/2, Screen.height * 3/8), easy, "easy");
if (easy)
{
normal = false;
hard = false;
Title.difficulty = 1;
}
normal = GUI.Toggle(new Rect(Screen.width/4, Screen.height * 5/16, Screen.width/2, Screen.height/4), normal, "normal");
if (normal)
{
easy = false;
hard = false;
Title.difficulty = 2;
}
hard = GUI.Toggle(new Rect(Screen.width/4, Screen.height * 9/16, Screen.width/2, Screen.height/4), hard, "hard");
if (hard)
{
normal = false;
easy = false;
Title.difficulty = 3;
}
if (easy || normal || hard)
{
if (GUI.Button(new Rect(Screen.width/4, Screen.height * 13/16, Screen.width/2, Screen.height/8), "Proceed"))
{
Application.LoadLevel("Home");
}
}
}
}
void Start() {
message = "THis is Text for trial slow slow";
text = "";
StartCoroutine(TypeText());
}
void Update() {
if (text == message){
textfin = true;
}
}
IEnumerator TypeText()
{
foreach (char letter in message.ToCharArray())
{
text += letter;
yield return new WaitForSeconds(letterPause);
}
}
答
+0
噢,我的上帝......我真的很抱歉,你说的对,我把剧本两次加到了现场。 .. Oppps。我只是看自己的脚本。对不起,我的错误:( –
我不知道你的变量'textfin'。难道不是跳过按钮被创建两次,处于相同的位置......您是否尝试使用可视化调试器或打印进行调试? – arainone
Opps我将脚本添加到了两个单独的对象中......它创建了两个按钮,就像你说的那样...... :( –