Im trying to write a foreach statement to find the transform for all the gameobjects in a list so i can get the x y onscreen location for each. i can white them all out 1 at a time like
Vector3 a = camera.WorldToScreenPoint(Targets[0].position);
float aX = a.x;
float aY = a.y;
but in each lvl of my game there is a different number of game objects. Any suggestions would be greatly appreciated.
you need to explain what you’re doing with all the transform positions, because normally you wouldn’t just find the positions, you would use the positions each for something, and you would include that in the loop to find them all.
in unity we mostly loop through the values in an array/list like this-
for (var i=0;i<targets.Length;i++){
var aX= targets*.transform.position.x*
var ay= targets*.transform.position.y* } and for (target in targets){ var aX= target*.transform.position.x* var ay= target*.transform.position.y* } At the end of the day you can access each element of the array at the same time as you use them for a calculation, rather than just converting them to a variable.