Search for Object with largest y-Coordinates

Hello there! I want to search for an Object in Objects with the same Tag who has the highes / largestt y-coordinates in the scene.
I know i could do it with put the objects when they spawn in an array and then ckeck with loops the highest position, but may there is a better way and smoother way.
I need this because my Camera needs to go move up on the y-coordinates if the objects pile and become more and more higher, other hints for my solutions would be great aswell. :slight_smile:

Ty for reading and coming answers, excuse my bad english.

Well, something is going to have to iterate through the objects in question and find the one with the largest Y value. You should be able to find the objects in question using something like:

 GameObject[] gos = GameObject.FindGameObjectsWithTag("yourTag");

Then, just spin through the objects in the returned array and find the one you’re interested in.

Alternatively, you could probably use some LINQ to get what you want. Caution - typed directly into the forum and completely untested…

GameObject go = GameObject.FindGameObjectsWithTag("yourTag")
   .OrderByDescending(go => go.transform.position.y).First();

If you choose to use some LINQ, you’ll need to add a “using System.Linq;” to the top of your file.