I am looking to be able to create reflection probe grids, being able to control the X, Y and Z amounts, but I have been unable to find any example of something like this, I have found grid examples, but not of objects.
Obviously, the X, Y and Z sizes (total sizes) would have to be dependent on the reflection probes sizes, which just adds another level of difficulty to it.
Does anyone have any ideas, or can point me to anything like this?
Seems like you basically need a 3-D array of objects, is that right? I mean, the fact that it’s a reflection probe is good to know, but it can be any object that you instantiate.
You will need a script on a separate object (often the parent transform of your probes, though it doesn’t have to be), and on Start(), it creates the clones. You’ll want 3 nested for loops, one for each dimension, and in each case you will calculate the new position based on the 3 loops.
Here’s a simple implementation:
public GameObject initialObject;
public Vector3 offsets = new Vector3(1,1,1);
public int xCount = 5;
public int yCount = 5;
public int zCount = 5;
void Start() {
for (int x=0;x<xCount;x++) {
for (int y=0;y<yCount;y++) {
for (int z=0;z<zCount;z++) {
if (x == 0 && y == 0 && z == 0) continue; // skip this loop, because the original object itself is at 0,0,0
Vector3 newPosition = initialObject.transform.position + new Vector3(offsets.x * x, offsets.y * y, offsets.z * z);
Instantiate(initialObject, newPosition, Quaternion.identity);
}
}
}
}