Create a Cube of Cubes

Hi There,
I thought of an idea and then wondered how I could get it into Unity and have hit a block, mainly because of my lack of mathematical ability. Perhaps someone can help on this…

Basically it is a Cube 1000x1000x1000 and is made up of smaller Cubes 1x1x1. I started placing Cubes beside each other and soon discovered… it’s going to take a while…Is there a mathematical quick way to do this?

That’s the first part. Then I need to texture each Cube individually. Is this even possible when there are so many? I need to be able to identify a Cube in a coordinate system and read it’s texture.

Thanks.

//This creates a large block of objects.
//Add script to an empty object. The creation of the this script will be in releation to where the empty block is placed.
var prefab : GameObject;
var cubeSize : int = 5 ;
var offset : int = 1 ; //Distance between cube centers

    function Start(){

        for (var zz = 0;zz<cubeSize*offset;zz+=offset){

           for (var yy = 0;yy<cubeSize*offset;yy+=offset){

             for (var xx = 0;xx<cubeSize*offset;xx+=offset){

                // Begin the instantiation where the empty object is. 
         		Instantiate (prefab, Vector3(transform.position.x + xx, transform.position.y + yy, transform.position.z + zz), Quaternion.identity);

                   //Added this line so you can actually see how the cubes are being populated
                  yield WaitForEndOfFrame;    

             }    
           }
        }
    }

You won’t be able to make 1000x1000x1000 separate objects, not even close. You realize that’s 1 billion objects, right? :wink: If you’re trying to do something like Minecraft, you have to build meshes using the Mesh class, and be smart about not creating geometry that you won’t see anyway.

I found a solution to this. An asset on the Asset Store called 'Endless Universe".

SPAWN A CUBE OF CUBES .

public Transform cubePrefab;

public int rows,columns,depth;
public float padding;

// Use this for initialization
void Start () {
	for(int i =0; i < depth; i ++) {
		for(int j=0;j< columns;j++){
			for(int k=0; k < rows;k++){
				Vector3 pos = new Vector3(k * padding,j * padding,i * padding);
				//print(pos);
				Transform foo = (Transform) Instantiate(cubePrefab,pos,Quaternion.identity);
			}
		}
	}
}