Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/339.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 在C语言中从数组中引用对象的组件#_C#_Arrays_Boolean_Components - Fatal编程技术网

C# 在C语言中从数组中引用对象的组件#

C# 在C语言中从数组中引用对象的组件#,c#,arrays,boolean,components,C#,Arrays,Boolean,Components,我试图通过使用player pref整数,从数组中选中/取消选中特定对象的可交互复选框。我遇到的问题是,我似乎无法引用数组中的特定对象,请帮助 下面是一些脚本: //This part is from the Start function. for (int i = 0; i < buttons.Length; i++) { if (PlayerPrefs.GetInt("button" + i) == null) { Play

我试图通过使用player pref整数,从数组中选中/取消选中特定对象的可交互复选框。我遇到的问题是,我似乎无法引用数组中的特定对象,请帮助

下面是一些脚本:

//This part is from the Start function.

for (int i = 0; i < buttons.Length; i++) {

            if (PlayerPrefs.GetInt("button" + i) == null) {

                PlayerPrefs.SetInt("button" + i, 1);

            }

            if (PlayerPrefs.GetInt("button" + i) == 1) {

                button.interactable = true;

            } else {

                button.interactable = false;

            }

        }



void Update () {

        for (int i = 0; i < buttons.Length; i++) {

            if (PlayerPrefs.GetInt("button" + i) == 0) {

                button.interactable = false;

            }

        }

    }
//此部分来自Start函数。
对于(int i=0;i

您可以看到button.interactiable=true/false的区域是我遇到问题的地方

如果您没有在其他地方定义
按钮
;我假设您缺少数组索引访问器的概念;您可能希望使用
按钮[i]
而不是
按钮

而不是在类中使用整数变量,您是否考虑过在类中只使用按钮的实例并将其显示在表单上?通过这种方式,你可以通过类的实例与按钮交互。天哪,它工作了。非常感谢:D抱歉,我对C#太陌生了,以至于我仍然习惯于不同内容所需的语法。