Hi I made a code that I will eventually use for stacking objects, but are at the moment just testing if it executes correctly which it doesn't and I can't seem to figure out what is wrong.
The Code:
var countx:int=0;
var county:int=0;
var countz:int=0;
function Update () {
while (county < 101){
++countx;
Debug.Log("1: "+countx+","+county+","+countz);
if (countx==200) {
++countz;
Debug.Log("2: "+countx+","+county+","+countz);
if (countz==200) {
++county;
countz=1;
Debug.Log("3: "+countx+","+county+","+countz);
}
if (county< 100)countx=1;
}
Debug.Log("4: "+countx+","+county+","+countz);
}
}
for (var countY=0; countY < 100; ++countY) {
for (var countZ=0; countZ < 200; ++countZ) {
for (var countX=0; countX < 200; ++countX) {
// Debug.Log(countX + ", " + countY + ", " + countZ);
}
}
}
(i.e. iterate through every point in a 200x200x100 structure?)
Using nested 'for' loops like this is the typical method for iterating through a 2d or 3d set, however the figures you have give a rather large number of total iterations. For this reason, I have the Debug.Log line commented out in my example, because if you run it, that code will generate 4 million debug.log lines (which may cause your computer to seem as though it has locked up while printing them all to the console).
Note, if you're planning to stack gameobjects using something like this, you'll end up with 200 x 200 x 100 objects - that's 4 million gameobjects - something that is not really feasible to work with in Unity.