Hi
i am trying to make a 3x3x3 cube of smaller cubes using 3 nested loop but i am getting weird results .
Here is the code :
#pragma strict
var cubemain : Transform; //a cube that exist in the scene
function Start ()
{
var maxL: int = 3;
var maxW: int = 3;
var maxH: int = 3;
for ( var x:int =0;x < maxL; x++ )
{
for ( var y:int = 0;y < maxH; y++ )
{
for ( var z:int = 0;z < maxW;z++ )
{
Instantiate(cubemain, Vector3 (x, y, z), Quaternion.identity);
}
Instantiate(cubemain, Vector3 (x, y, z), Quaternion.identity);
}
Instantiate(cubemain, Vector3 (x, y, z), Quaternion.identity);
}
}
Instead of getting the 3x3x3 cube i am geting something like this a 3x3x4 and another row on top at one of the edges .
looks something like this :

From what i can see is that for some reason the loops are not executed as they should .
I have tried using while loops , no go .
Before you ask , i tried using a prefab and unity hangs .
Tried this on Unity pro trial and on Unity free version same result .
Did this on 2 different computers , with AMD processors and windows 7 .
Am i doing something wrong or is this a Unity compatibility problem ?
Thanks in advance for your help .