我開始學習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);
}
}
我不知道你的變量'textfin'。難道不是跳過按鈕被創建兩次,處於相同的位置......您是否嘗試使用可視化調試器或打印進行調試? – arainone
Opps我將腳本添加到了兩個單獨的對象中......它創建了兩個按鈕,就像你說的那樣...... :( –