|
On an empty game object I have a script that is trying to instantiate a creation of a large block created from several smaller blocks. I'm trying to instantiate a block of 10x10x10 of cubes 2m apart. ((This is only for my understanding of how to do this correctly. I could just make a prefab and call that once, but I'm curious as to how this could be solved.)) Here's my bad attempt at solving this problem. for (var i : int = 0;i < 10; i++) { Instantiate (prefab, Vector3(i * 2, 0, 0), Quaternion.identity); Instantiate (prefab, Vector3(0, i * 2 + 1, 0), Quaternion.identity); Instantiate (prefab, Vector3(0, 0, i * 2 + 1), Quaternion.identity); } This only makes a 10x10x10 along the x,y,z lines, however I can see right away that I'm messing up somehow as the first position of the y and z aren't in the correct location.
(comments are locked)
|
|
It's probably best to use 3 for loops here, one for each dimension. Something like; This builds a row along x first, (for 10) then generates 10 of those rows along y(for 10x10), then duplicates the two of those along z (for 10x10x10). Think that should work. Happy new year!
(comments are locked)
|
|
A great reminder of how far I have to go in my programming. Thanks AtomicHippo! Also, Love the yield WaitForEndOfFrame function!
(comments are locked)
|

I'm really not great at for loops but I think the reason your y and z prefabs aren't being instantiated at the right position is because you are saying i*2+1 and since i is 0 the first time (I think) you are practically saying 0*2+1 which will equal 1. Since you want it to appear at 0 and not 1 you might have to remove the +1. This might get you started =)