有申请表吗。在C#中同时关闭图片和文本?

有申请表吗。在C#中同时关闭图片和文本?,c#,unity3d,C#,Unity3d,我正在为我的主菜单编写一个Unity程序。我有退出按钮,只需要 public void ExitGame() { Application.Quit(); } 但我需要的东西只能从窗口退出,不能从游戏中退出。是应用程序。退出,我只是偏执狂?或者是我不知道的事情。请帮忙 编辑:会吗 public void ExitOptions() { optionMenu.enabled = false } 工作? 编辑2:我被要求在这里添

我正在为我的主菜单编写一个Unity程序。我有退出按钮,只需要

public void ExitGame()
    {

        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
    }
}
使用UnityEngine;
使用UnityEngine.UI;
使用系统集合;
公共类菜单脚本:单一行为{
公共菜单;
公共按钮开始文本;
公共按钮退出文本;
公共画布选项菜单;
公共按钮WASDText;
公共按钮箭头文本;
//用于初始化
无效开始()
{
quitMenu=quitMenu.GetComponent();
startText=startText.GetComponent();
exitText=exitText.GetComponent();
quitMenu.enabled=false;
optionMenu=optionMenu.GetComponent();
WASDText=WASDText.GetComponent();
arrowText=arrowText.GetComponent();
}
公共无效退出按钮()
{
quitMenu.enabled=true;
startText.enabled=false;
exitText.enabled=false;
}
公开作废期权出版社()
{
optionMenu.enabled=true;
WASDText.enabled=true;
arrowText.enabled=false;
}
公共图书馆
{
optionMenu.enabled=false;
startText.enabled=true;
exitText.enabled=true;
}
公共空间WASDPress()
{
optionMenu.enabled=true;
WASDText.enabled=true;
arrowText.enabled=false;
}
公共新闻界()
{
optionMenu.enabled=true
WASDText.enabled=false
arrowText.enabled=true
}
公共级别()
{
应用程序加载级别(1);
}
公共无效ExitGame()
{
Application.Quit();
}
公共无效退出()
{
optionMenu.enabled=false
}
}

如果
文本
组件嵌套在
图像
组件中,只需调用:

optionMenu.SetActive(false);
它将使它与其所有子项一起处于非活动状态

如果要从另一个Unity3D UI元素关闭它,可以附加
事件触发器
,或者如果它是
按钮
,则可以将
图像
拖放到它的
OnClick()
事件,并保持复选框未选中(在下面的示例中,它将启用名为“Canvas2”的对象,因为复选框已选中):


可能需要使用
this.Close()
,但不清楚退出窗口而不是游戏是什么意思。你的意思是你正在使用一个GUI组件,你想关闭它吗?您能为定义了
ExitGame
方法的类显示更多的代码吗?我使用的是带有文本的UI图像作为子对象。我不明白你的意思,但这里是脚本,我计划在完成后将其分为两个不同的脚本。当我完成后,我将制作一个更简洁的简短版本。请在问题中添加所有这些源代码。评论是为了解决疑问。你把问题搞得一团糟,好吧。我会的。