无法使用实例引用FindGameObjectsWithTag访问

时间:2017-02-09 20:53:40

标签: c# unity3d

第一个foreach抛出错误。我正在尝试使用FindGameObjectsWithTag快速查找我的所有SubMenu项目。 起初我使用GameObject.FindFindGameObjectsWithTag("SubMenu")),它似乎工作(没有错误),但它实际上没有在场景中做任何事情。我将它更改为UIButtons,因为这是我所有菜单按钮的集合,希望它能真正做到。

我无法弄清楚如何纠正这个错误,即使在研究了其他类似错误的人问题之后也是如此。我是c#和Unity的初学者,所以如果有人能够朝着正确的方向推动我,那将非常有帮助。

void Start () {
    buttons = new List<GameObject>();
    foreach (var btn in UIButtons.FindGameObjectsWithTag("SubMenu"))
    {
        buttons.Add(btn);
    }

    foreach (var btn in buttons)
    {
        Button btn2 = btn.GetComponent<Button>();
        btn2.enabled = false;
        btn2.image.color = new Color(0f, 0f, 0f, 0f);
        Text text = btn2.GetComponentInChildren<Text>();
        text.text = "";
    }
}

0 个答案:

没有答案
相关问题