I just started using Unity and I’ve run into little bit of hurdle.
I wanted to make 3D array to store state of cellular automaton, a task which was trivial in C++, unfortunately despite my best efforts the script throws
IndexOutOfRangeException: Array index is out of range.
(wrapper managed-to-managed) object:ElementAddr (object,int,int,int)
array.Start () (at Assets/array.js:6)
error. While I understand what error means I don’t understand while following code
public var mat:int[,,] = new int[100,100,100];
function Start () {
for(var x : int = 0; x < mat.Length; x++){
for(var z : int = 0; z < mat.Length; z++){
for(var y : int = 0; y < mat.Length; y++){
mat[x,z,y] = binRandom();
}
}
}
}
function binRandom(){
var n;
var x = Random.Range(0.0, 1.0);
if (x < 0.5){
n = 1;
}
if (x > 0.5){
n = 0;
}
return n;
}
produces it.
Somewhat related to that is trouble I’ve been having with Monodevelop debugger.
When I attach it to unity editor and then run the game the entire application freezes and process has to be terminated. I have been following instruction from Unity manual so I don’t know where the problem is.
Thank you for replies.