- Home /
[Solved] Error when trying to add a boolean array variable to GUI Toggle
Hello!
I've small problem with adding boolean array variable to GUI.Toggle.. "IndexOutOfRangeException: Array index is out of range" Here's the code:
#pragma strict
var texturequality : boolean[] = new boolean[4];
function Start(){ //deleting this doesn't help
texturequality[0] = true;
texturequality[1] = false;
texturequality[2] = false;
texturequality[3] = false;
}
function OnGUI(){
texturequality[0] = GUI.Toggle(Rect(Screen.width/1.5-60,Screen.height/8.5+20,14,20),texturequality[0],"");
texturequality[1] = GUI.Toggle(Rect(Screen.width/1.5-30,Screen.height/8.5+20,14,20),texturequality[1],"");
texturequality[2] = GUI.Toggle(Rect(Screen.width/1.5,Screen.height/8.5+20,14,20),texturequality[2],"");
texturequality[3] = GUI.Toggle(Rect(Screen.width/1.5+30,Screen.height/8.5+20,14,20),texturequality[3],"");
}
Any help?
Answer by Datates · Jan 07, 2014 at 09:06 PM
Since you're using javascript, texturequality is accessible from the editor and is not initialized properly from the code (you probably declared it without length at first, then changed it later on).
Check the length of the array in the inspector. Is it set to 0? Set it to 4 and try again.
If you want to initialize it from the code, make the array private.
Your answer
Follow this Question
Related Questions
Setting Scroll View Width GUILayout 1 Answer
Can someone help me fix my Javascript for Flickering Light? 6 Answers
Limit on GUI Components? 0 Answers
Android touch gui help!!! 2 Answers
GUI.Button Quality Change. 1 Answer