how do i instantiate multiple object object with line change with for loop.

hi boys and girls

how do i instantiate multiple object object with line change with for loop.

i am totally noob but in documents.

 for (int i = 0; i < 10; i++)
            Instantiate(prefab, new Vector3(i * 2.0f, 0, 0), Quaternion.identity);

there is this.

so if i want instantiate 30 prefabs do i just

for (int i = 0; i < 3; i++)
			Instantiate(prefab, new Vector3(i * 1f, 0, 0), Quaternion.identity);
		for (int i = 0; i < 3; i++)
			Instantiate(prefab, new Vector3(i * 1f, 1, 3), Quaternion.identity);
		for (int i = 0; i < 3; i++)
			Instantiate(prefab, new Vector3(i * 1f, 2, 6), Quaternion.identity);

do i do it this way or is there simpler way. and if so how do i center the prefabs.

there was this it centers the prefabs but i dont know how do i do the line change

thanks.

You already use loops to set the x coordinate. Do it for y as well. You don’t really explain what you mean by centering, but if your objects are 1 unit wide like you code suggests, just don’t start from 0,0 but instead from negative coordinates by a sufficient amount

int xCount = 3;
int yCount = 3;
float xCentering = -(xCount - 1) / 2f;
float yCentering = -(yCount - 1) / 2f;

for (int x = 0; x < xCount; x++) {
    for (int y = 0; y < yCount; y++) {
             Instantiate(prefab, 
                   new Vector3(x + xCentering, y + yCentering, 0), 
                   Quaternion.identity);
    }
}