gpt4 book ai didi

c# - 是否有应用程序。在 C# 中关闭图片和文本?

转载 作者:太空宇宙 更新时间:2023-11-03 23:25:21 24 4
gpt4 key购买 nike

我正在用 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
}
}

最佳答案

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

optionMenu.SetActive(false);

这将使它与其所有子项一起处于非事件状态。

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

enter image description here

关于c# - 是否有应用程序。在 C# 中关闭图片和文本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33989318/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com