# Grid generation problem

I have been trying to generate a grid, which I did. But the properties that I enter into the quantity variable, it doesn’t spawn the number I type in, instead, it adds it to the starting position I typed before. I’d like it to spawn the number is being set.

``````public class GenerationOfTiles : MonoBehaviour {
public GameObject block;
public float posX;
public float posY;
public float quantityx = 10;
public float quantityy = 10;
private float startupx = -7f;
private float startupy = -12f;
// Use this for initialization
void Start () {

for (float x = startupx;x < quantityx; x += posX) {

for(float y = startupy;y < quantityy; y += posY) {

Instantiate(block,new Vector3(x,y,0),Quaternion.identity);

}

}
}
// Update is called once per frame
void Update () {

}
}
``````

I think you want to do something like this?

``````public class GenerateGrid
{

int numberX = 10;        //    Number of tiles on direction X.
int numberY = 10;        //    Number of tiles on direction Y.
float dx = 1.0f;        //    X length of each tile.
float dy = 1.0f;        //    Y length of each tile.
float x0 = -5;            //    X position of first tile.
float xy = -5;            //    Y position of first tile.

void Start ()
{
for (int i = 0; i < numberX; i++) {
for (int j = 0; j < numberY; j++) {
Vector3 position = new Vector3(x0 + i * dx, y0 + j * dy, 0);        //    Position of tile[i,j].
}
}
}
}
``````

This will generate a grid with 10 tiles on x, 10 tiles on y, starting at (-5,-5,0) and ending at (5,5,0).
Note that each tile will have its position assigned to its lower left corner, so the last tile will have (4,4,0) as lower left corners and (5,5,0) as upper right corners.
If you want this position to be centered you could just offset the start i think.