通过标记禁用一组按钮的可交互状态



我的游戏区有两组按钮,我想在它们之间切换。目前,我在编辑器中对每个组进行了不同的标记,并且我还有另一个按钮,我打算将其用作切换按钮,以交换可以与哪些按钮进行交互。这是我目前得到的,但运气不好。我在isinteractitable行上得到错误:没有重载方法IsInteractable' takes '参数。

我哪里错了?

    if(keySet == true)
    {
        // turn ON Interactable for Alpha buttons
        for(int i = 0; i > GameSetup.alphaKeys.Length; i++)
        {
            GameObject alphaButton = GameObject.FindGameObjectWithTag("AlphaKey");
            alphaButton.GetComponent<UnityEngine.UI.Button>().IsInteractable(true);
        }
        // turn OFF Interactable for Shape buttons
        for(int i = 0; i > GameSetup.symbolKeys.Length; i++)
        {
            GameObject alphaButton = GameObject.FindGameObjectWithTag("SymbolKey");
            alphaButton.GetComponent<UnityEngine.UI.Button>().IsInteractable(false);
        }
    }
    else
    {
        // Do the reverse if false
    }

明白了!我为每一组按钮添加了一个Canvas Group组件,这使得控制我需要访问的所有属性变得超级容易。

public void HandleActiveKeySet (bool keySet)
{
    if(keySet == true)
    {
        GameObject alphaGroup = GameObject.FindGameObjectWithTag("AlphaGroup");
        alphaGroup.GetComponent<CanvasGroup>().interactable = true;
        alphaGroup.GetComponent<CanvasGroup>().blocksRaycasts = true;
        GameObject symbolGroup = GameObject.FindGameObjectWithTag("SymbolGroup");
        symbolGroup.GetComponent<CanvasGroup>().interactable = false;
        symbolGroup.GetComponent<CanvasGroup>().blocksRaycasts = false;
    }
    else
    {
        GameObject alphaGroup = GameObject.FindGameObjectWithTag("AlphaGroup");
        alphaGroup.GetComponent<CanvasGroup>().interactable = false;
        alphaGroup.GetComponent<CanvasGroup>().blocksRaycasts = false;
        GameObject symbolGroup = GameObject.FindGameObjectWithTag("SymbolGroup");
        symbolGroup.GetComponent<CanvasGroup>().interactable = true;
        symbolGroup.GetComponent<CanvasGroup>().blocksRaycasts = true;
    }
}

相关内容

  • 没有找到相关文章

最新更新