我开始学习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 :(得分:3)