Unity3d SetActive未被识别?

Unity3d SetActive未被识别?,unity3d,Unity3d,所以是的,我试图在unity上做一个小游戏,创建一个暂停菜单,当我创建一个带有GameObject的变量时,我不能使用SetActive,它基本上说SetActive无法识别 代码如下: bool IsPaused; GameObject[] Pause_Menu; // Start is called before the first frame update void Start() { IsPaused = false; Pause_Menu = GameObject.F

所以是的,我试图在unity上做一个小游戏,创建一个暂停菜单,当我创建一个带有
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_菜单定义为单个游戏对象,而不是游戏对象数组,并将
FindGameObjectsWithTag
更改为
FindGameObjectWithTag
(删除“s”)。甚至更短的版本
FindWithTag
,如:

Pause_Menu = GameObject.FindWithTag ( "Pause_Menu" );

这是您的Unity文档。

好的,谢谢!但是,如果我想一次禁用所有带有此标记的游戏对象,该怎么办?这不是直接回答您的问题,但是,在您的层次结构中,简单地
SetActive(true/false)
a父对象作为一个组打开和关闭整个菜单项集是否有意义?@LeFauconQC如果这回答了您的问题,请将其标记为已回答,在下面画一条线。干杯