- Home /
Find Closest Object by Name
Hi, because the tags on my target Objects are in use, I'm currently searching the targets by name. But now I have the problem of sorting them by their position in relation to me...
I could try to find a fixed number of targets, make sure there are all different and then put them into an array and sort the array with: targets = targets.OrderBy(obj => (obj.transform.position this.transform.position).sqrMagnitude).ToArray();
But I am not sure if this is the right attempt or if there is a more efficient way of doing this?
I also don't know how I would search the targets without flooding my script with endless lines of Boolean comparisons...
Thanks for your help in advance
Your answer
![](https://koobas.hobune.stream/wayback/20220612044207im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
GameObject.Find can't find the object after i changed her name 1 Answer
How do I find the closest target with a tag? c# 2 Answers
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Is there a way to load all objects in multiple folders within a Resource folder into 1 array? 1 Answer