- Home /
Instantiate Prefabs on "Grid" Pattern?
Hey! I want to instantiate a unknown number of prefabs on a pattern. They should spawn in a specific area which has the Form of a funnel/hopper or a half circle like this
so how do i instantiate x prefabs that they don't get placed over each other and also on a specific pattern
Just use normal instantiate in a for loop ? You can tell every instantiate object what it position in x y and z should be
Answer by Ali-hatem · Apr 29, 2016 at 12:15 PM
Vector3[] pos;
public GameObject [] obj;
void Start(){
for (int i = 0; i < obj.Length; i++) {
pos = new Vector3[obj.Length];
pos[0] = new Vector3(transform.position.x + i, transform.position.y, transform.position.z);
pos[1] = new Vector3(transform.position.x + i, transform.position.y-1, transform.position.z);
//etc...
Instantiate (obj [i], pos[0], transform.rotation);
Instantiate (obj [i], pos[1], transform.rotation);
//etc...
}
}
add number to transform.position.y
to make new row . & miniplate the object scale to reduce gap between objects .
Your answer
Follow this Question
Related Questions
I want to respawn the food everytime the snake collides with it 0 Answers
Instantiate over time? 1 Answer
Problem with spawn object 0 Answers
Why do objects keep spawning on top of one another? 0 Answers
Spawn and set as child 2 Answers