【发布时间】:2015-11-30 07:50:07
【问题描述】:
我正在为我的主菜单在 Unity 中编写一个程序。我得到了退出按钮,它只需要
public void ExitGame()
{
Application.Quit();
}
但我需要一些只退出窗口而不是游戏的东西。是Application.Quit,我只是偏执吗?或者是我不知道的东西。请帮忙!
编辑:会
public void ExitOptions()
{
optionMenu.enabled = false
}
工作? 编辑2:我应该在这里添加代码:写完后我会做一个更简洁的版本
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
public class menuScript : MonoBehaviour {
public Canvas quitMenu;
public Button startText;
public Button exitText;
public Canvas optionMenu;
public Button WASDText;
public Button arrowText;
// Use this for initialization
void Start ()
{
quitMenu = quitMenu.GetComponent<Canvas>();
startText = startText.GetComponent<Button>();
exitText = exitText.GetComponent<Button>();
quitMenu.enabled = false;
optionMenu = optionMenu.GetComponent<Canvas>();
WASDText = WASDText.GetComponent<Button>();
arrowText = arrowText.GetComponent<Button>();
}
public void ExitPress()
{
quitMenu.enabled = true;
startText.enabled = false;
exitText.enabled = false;
}
public void OptionPress()
{
optionMenu.enabled = true;
WASDText.enabled = true;
arrowText.enabled = false;
}
public void NoPress()
{
optionMenu.enabled = false;
startText.enabled = true;
exitText.enabled = true;
}
public void WASDPress()
{
optionMenu.enabled = true;
WASDText.enabled = true;
arrowText.enabled = false;
}
public void ArroPress()
{
optionMenu.enabled = true
WASDText.enabled = false
arrowText.enabled = true
}
public void StartLevel()
{
Application.LoadLevel (1);
}
public void ExitGame()
{
Application.Quit();
}
public void ExitOptions()
{
optionMenu.enabled = false
}
}
【问题讨论】:
-
可能需要使用
this.Close(),但不清楚退出窗口而不是游戏是什么意思。你的意思是你正在使用一个 GUI 组件并且你想关闭它?你能展示更多定义ExitGame方法的类的代码吗? -
我正在使用带有文本的 UI 图像作为子项。我不明白你的意思,但这是脚本,我打算在完成后将它分成两个不同的脚本
-
完成后我会制作一个更简洁的短版
-
请在问题中添加所有这些源代码。评论是为了解决疑问。你把问题弄得一团糟。
-
好的。我会这样做的。