Question by
ExtinctChicken · Apr 11, 2017 at 05:29 PM ·
c#instantiatefor-loop
Instantiating more than one column(array)?
Hi everyone,
I've come up with a way to instantiate a specified amount of objects in a grid-like manner. For example, If I want 10 cubes placed exactly side by side(10 units apart from each other), I instantiate the cubes like such:
public GameObject basePrefab;
public int columnSize = 3;
public GameObject[] column;
// Use this for initialization
void Start () {
column = new GameObject[columnSize];
InstantiateBase(columnSize, basePrefab);
}
void InstantiateBase(int c, GameObject b) {
Vector3 startPos = new Vector3(0, 0, 0);
for(int i = 0; i < c; i++) {
GameObject newBase = Instantiate(b, startPos + (Vector3.left * 10 * i), Quaternion.identity) as GameObject;
}
}
But this only instantiates the cubes in a straight line. How do I make it so that it instantiates like a grid? so multiple columns at a time?
Comment