Place objects Mathematically

Hi There, In Unity’s Editor I need to fill a Cubic area with Cubes spaced 27 meters apart. The area is 729x729x729 so the first Cube is at 0,0,0 and the others which I calculate (please correct me if I’m wrong) to be 19,683 in number are evenly spaced out to the Cubic perimeter.
I figure that 19,683 Cubes is well within Unity’s capability and so I’m wanting to place these Mathematically. Can someone describe how to do this please? Thanks.

public GameObject cube;
void Start ()
{
for(int i=0;i<=729;i+=27)
{
for(int j=0;j<=729;j+=27)
{
for(int k=0;k<=729;k+=27)
{
Vector3 pos = new Vector3(i,j,k);
Instantiate(cube,pos,transform.rotation);
}
}
}
}

This is working fine. But will take time to execute because of leangthy for loops.You will get the cubes equally placed 27 units apart from eachother. Let me know if not working.

I don’t know if I understood every detail of the problem there, but here’s something to instantiate an object repeatedly in 3 dimensions :

var cube : GameObject; //the cube that you want to replicate. It should be  a prefab or already in scene



   function Start(){  //start making the cube

	for(var i = 0 ; i < 29; i ++){
	
		for(var j = 0 ; j < 29 ; j ++){
		
			for(var k = 0 ; k < 29 ; k ++){
			
				Instantiate(cubePrefab, Vector3(transform.position.x + (k * 29), transform.position.y + ( j * 29), transform.position.z + ( i * 29)), transform.rotation);
				
			}
			
			if(j == 6 || j == 12 || j == 18 || j == 24)
				yield WaitForSeconds(0.1);  //you can reduce 0.1 to 0.05 or something if you think that the cubes are taking too long to form
		}
		if(i == 6 || i == 12 || i == 18 || i == 24)
			yield WaitForSeconds(0.1);  // same as the above comment
		
	}
    }	

This will form a large cube consisting of 5 x 5 x 5 = 125 cubes, which are all 3 meters apart from each other.

I Hope this helps! Try out the script and let me know!

this is how i would do it (in pseudocode)

cubePosition = (0,0,0)
   loop y {
     loop z {
       loop x {
         cubePosition.x += 27;
         instantiate(cube, rotation, cubePosition)   --i guess you'd want to work with instances with so many objects!
       }
     cubePosition.x = 0;
     cubePosition.z += 27;
     }
   cubePosition.z = 0;
   cubePosition.y += 27;
   }