Why are my objects instantiating inside eachother?

I have this code:

for(int i = 0; i < 5; i++){
				print ("?" + i+1);
				Instantiate(Prefab, new Vector3(rowN2, -2.5f + i + 10, 0), Quaternion.identity);
				Instantiate(Prefab, new Vector3(row2, i, 0), Quaternion.identity);
			}

They are both spawning 5 objects, 1 alone and then 2 by 2 spawned inside eachother, how can I avoid this?

1 Answer

1

In this line

Instantiate(Prefab, new Vector3(rowN2, -2.5f + i + 10, 0), Quaternion.identity);

the difference between the y positions of two game objects being spawned is increased by 1 only which seems to be a small value compared to other values affecting it.

You must be looking at multiplying with i like:

Instantiate(Prefab, new Vector3(rowN2, -2.5f * i + 10, 0), Quaternion.identity);

Same might be true for second Instance, where the i value needs to influence the positing values (if required).

If you could post how you want to position these instantiated objects then we can provide precise logic.