我在 Unity 3D 上开发,并尝试使用此处实现的类制作一个 Combobox
现在在我的测试课上,我这样做:
public class combobox_test : MonoBehaviour {
public GUIContent[] comboBoxList;
private ComboBox_Class comboBoxControl = new ComboBox_Class();
public GUISkin mySkin;
void start(){
comboBoxList = new GUIContent[5];
comboBoxList[0] = new GUIContent("Thing 1");
comboBoxList[1] = new GUIContent("Thing 2");
comboBoxList[2] = new GUIContent("Thing 3");
comboBoxList[3] = new GUIContent("Thing 4");
comboBoxList[4] = new GUIContent("Thing 5");
}
void OnGUI(){
GUI.skin = mySkin;
int selectedItemIndex = comboBoxControl.GetSelectedItemIndex();
selectedItemIndex = comboBoxControl.List(new Rect(50, 100, 100, 20), comboBoxList[selectedItemIndex].text, comboBoxList,GUI.skin.GetStyle(""));
//GUI.Label( new Rect(50, 70, 400, 21),"You picked " + comboBoxList[selectedItemIndex].text + "!" );
}
}
我有这个错误:
IndexOutOfRangeException:数组索引超出范围。combobox_test.OnGUI () (在 Assets/combobox_test.cs:56)
我尝试了一些在不同网站上找到的解决方案,但没有任何效果。