I wrote C # Script in Unity, which detects all visible objects. Now I would like to display them from left to right, as they are located on the stage. Each object has a number, but Script displays the objects in ascending order.
My idea:
I was thinking of a for-loop that goes across a horizontal field of view. First, calculate the horizontal FOV by:
private static float horizontalFOV() { float radAngle = Camera.main.fieldOfView * Mathf.Deg2Rad; float radHFOV = 2 * Mathf.Atan(Mathf.Tan(radAngle / 2) * Camera.main.aspect); float hFOV = Mathf.Rad2Deg * radHFOV; return hFOV; }
And creating a loop:
public static string OutputVisibleRenderers (List<Renderer> renderers) { float hFov = horizontalFOV (); if (null == renderers) throw new System.ArgumentNullException ("renderers are null"); for (int i = 0; i < hFov; i++) { foreach (var renderer in renderers) { if (IsVisible (renderer)) { myList.Add (renderer.name); } } } string itemsInOneLine = string.Join ("-", myList.ToArray()); myList.Clear (); print (itemsInOneLine); print ("--------------------------------------------------"); return itemsInOneLine; }
But unfortunately, this will not work. So how could I read all objects from left to right?
source share