Hey all, the compiler tells me that my array is out of range when it is clearly not. Here are the important parts of the code:
public var cubeInstance = new GameObject[16];
public var nodeInstance = new GameObject[400];
var nodeIsInstantiated = new boolean[400];
var cubeIsInstantiated = new boolean[16];
....
function CalculateNodes() {
for (var a : int = 0; a < 16; a++) {
....
if (cubeIsInstantiated[a] && a > 11 && !nodeIsInstantiated[a+24]) { //top, 4-7
nodeIsInstantiated[a+24] = true;
--> nodeInstance[a+24] = Instantiate(Resources.Load("Node_prefab"), cubeInstance[a].transform.position + new Vector3(0,.5,0), new UnityEngine.Quaternion());
}
else if (!cubeIsInstantiated[a] && a > 11 && nodeIsInstantiated[a+24]) {
--> Destroy(nodeInstance[a+24]);
nodeIsInstantiated[a+24] = false;
}
....
}
… where code is omitted
→ where the compiler gives me the error
The compiler error:
IndexOutOfRangeException: Array index is out of range.
(wrapper stelemref) object:stelemref (object,intptr,object)
Main.CalculateNodes () (at Assets/Scripts/Main.js:131)
Main.OnGUI () (at Assets/Scripts/Main.js:92)
UnityEditor.Toolbar:OnGUI()
(same for both lines)
Note also that I successfully try to call a variable with the exact same array size on the lines next to the ones that the compiler rejects.
Pls halp!