I am writing a program in Unity for my main menu. I got the Quit button, it just takes
public void ExitGame()
{
Application.Quit();
}
But I need something that only exits the window not the game. Is it Application.Quit and I'm just paranoid? Or is something that I don't know of. Please help!
Edit: Would
public void ExitOptions()
{
optionMenu.enabled = false
}
work? Edit 2: I'm suposed to add code here: I will make a short cleaner version after I'm done writing it
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
}
}
If Text
component is nested in Image
component, justs call:
optionMenu.SetActive(false);
It will make it inactive along with all of its children.
If you are closing it from another Unity3D UI element, you can attach EventTrigger
or if it is a Button
, you can drag and drop Image
to it's OnClick()
event and leave checkbox unchecked (in example below it will enable object of name "Canvas2" beacause checkbox is checked):
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.