# How to shorten the distance between objects in an array?

I found the following code for making an array of cubes:

``````var cube : GameObject;
var x = 100;
var z = 100;

function Start () {
for (i = 0; i < x; i++) {
for (j = 0; j < z; j++) {
Instantiate(cube, Vector3(i, 0, j), Quaternion.identity);
}
}
}

function Update () {

}
``````

I’ve tried it, and it works, but the cubes are reaaaaally far apart. Could someone please tell me how to modify this code in order to instantiate the cubes with less space between them. I realise I could just increase the size of the prefab, but I’d like to learn how to do it this way.

Thanks!

You can control the distance - and even the position - in the world this way:

```var cube : GameObject;
var x = 100;
var z = 100;
var distX: float = 0.5; // set the distance in X
var distZ: float = 0.5; // set the distance in Z
var pos0: Vector3 = Vector(0, 0, 0); // lower left cube position

function Start () {
for (i = 0; i < x; i++) {
for (j = 0; j < z; j++) {
var pos = pos0 + Vector3(i*distX, 0, j*distZ);
Instantiate(cube, pos, Quaternion.identity);
}
}
}
```

HOW TO EDIT A PREFAB: drag it to the scene, modify whatever you want and click the Apply button in the Inspector to update the prefab - you can then delete the scene object, if you don’t need it anymore.