unity3d - SetActive 无法识别?
问题描述
所以是的,我正在尝试制作一个统一的小游戏,创建一个暂停菜单,当我创建一个带有 a 的变量时GameObject
,我不能使用SetActive
它,它基本上说它SetActive
无法识别。
这是代码:
bool IsPaused;
GameObject[] Pause_Menu;
// Start is called before the first frame update
void Start()
{
IsPaused = false;
Pause_Menu = GameObject.FindGameObjectsWithTag("Pause_Menu");
}
// Update is called once per frame
void Update()
{
Pause_Menu.SetActive(IsPaused);
if (Input.GetKeyDown("escape"))
{
IsPaused = true;
}
if ((Input.GetKeyDown("escape")) && (IsPaused = true))
{
IsPaused = false;
}
}
解决方案
当您使用FindGameObjectsWithTag
.
你可能想要的是这样的:
bool IsPaused;
GameObject Pause_Menu;
// Start is called before the first frame update
void Start ( )
{
IsPaused = false;
Pause_Menu = GameObject.FindGameObjectWithTag ( "Pause_Menu" );
}
// Update is called once per frame
void Update ( )
{
Pause_Menu.SetActive ( IsPaused );
if ( Input.GetKeyDown ( "escape" ) )
{
IsPaused = true;
}
if ( ( Input.GetKeyDown ( "escape" ) ) && ( IsPaused = true ) )
{
IsPaused = false;
}
}
将 Pause_Menu 定义为单个游戏对象,而不是游戏对象数组,然后更改FindGameObjectsWithTag
为FindGameObjectWithTag
(删除“s”)。甚至更短的版本FindWithTag
,如:
Pause_Menu = GameObject.FindWithTag ( "Pause_Menu" );
这是FindWithTag的 Unity 文档。
推荐阅读
- c# - C# Socket 监听器不绑定到端口
- python - argparse,但用于标准输入
- php - Wordpress / 在自己的插件中添加几个输入
- android-studio - Android Studio:Gradle 构建任务在哪里定义?
- groovy - Groovy:通过数组列表中的特定标签查找最便宜的价格
- c# - 重构嵌套的 foreach 语句
- json - 从 json 数据填充的下拉列表
- sql - 通过加入4个表来更新sql表
- python - Windows的stdout readlines挂起python 3.4
- python - OpenPose 库 - 设置问题