How in the world do I display GameObjects from an array in an equal y distance to eachother
Hey so I have been trying to work this out and I had an idea but I just realized it probably was a dumb idea hah
void Update()
{
points = GameObject.FindGameObjectsWithTag("-5");
for (int i = 0; i < points.Length; i++)
{
foreach (GameObject point in points)
{
point.transform.position = new Vector3(transform.position.x, transform.position.y - (20 * i), transform.position.z);
}
}
}
this was my code. so I'm trying to lay out game objects the same distance away from the ones next to it. like a line of them. ya know what I mean? would be awesome to have some help
Comment
Best Answer
Answer by Hellium · Apr 02, 2021 at 05:34 PM
for (int i = 0; i < points.Length; i++)
{
GameObject point = points[i];
point.transform.position = new Vector3(transform.position.x, transform.position.y - (20 * i), transform.position.z);
}
Answer by djenningsais · Apr 02, 2021 at 02:49 PM
This should be achievable.
To start off, nested for loops are potentially detrimental to application performance and should be avoided. .
I would remove the for loop and declare a variable outside of your foreach loop in order to track the current y coordinate or index if you want to use the same position implementation you currently have.
Hope this helps!!