- Home /
FInd the min and max position of children?
Hello,
I have four children to a parent. They all stick together wherever they go. The children are placed on the right, left, up and down with respect to the parent. Due the rotation of the parent, at any point I would like to find the child which occupies the minimum/Maximum X position and the minimum/maximum Z Position among everything.
What is the best way to solve it or is there any in-built Unity3d function which could grant access to find my child position or even compare the position with all the children and find the min and max?
Any help or advice is highly appreciated.
Thank you Devs
GAME : Top-Down View. i.e. along x and z axis.
P.S. :If you devs recommend to keep it simple, first I would like to find the min then.
Answer by whydoidoit · Jun 14, 2012 at 07:38 PM
Can't test this as I'm currently reimporting all my game assets :( - But this should do it:
using System.Linq;
var leftMost = transform.Cast<Transform>().OrderBy(t=>t.position.x).First();
var topMost = transform.Cast<Transform>().OrderBy(t=>t.position.z).First();
Just a curiousity question but...how's the compatibility for Linq across different platforms? I've been straying away from using it because my boss wants VERY high compatibility, and I can't seem to find any nice resources detailing it.
It's compatible on US and C# so long as you don't use the $$anonymous$$i mscorlib.dll
It will work find on an iPad - it certainly does for me :)
Sorry about the x/z mix up!