【问题标题】:Is there a Application. that closes both a picture and text in C#?有没有申请。在 C# 中同时关闭图片和文本?
【发布时间】: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 图像作为子项。我不明白你的意思,但这是脚本,我打算在完成后将它分成两个不同的脚本
  • 完成后我会制作一个更简洁的短版
  • 请在问题中添加所有这些源代码。评论是为了解决疑问。你把问题弄得一团糟。
  • 好的。我会这样做的。

标签: c# unity3d


【解决方案1】:

如果Text组件嵌套在Image组件中,则调用:

optionMenu.SetActive(false);

它会让它和它的所有子节点一起处于非活动状态。

如果您要从另一个 Unity3D UI 元素关闭它,您可以附加 EventTrigger 或者如果它是 Button,您可以将 Image 拖放到它的 OnClick() 事件中并取消选中复选框(例如下面它将启用名称为“Canvas2”的对象,因为选中了复选框):

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多