I have a hitCollider like this:
hitColliders = Physics.OverlapSphere(center, radius, 1 << LayerMask.NameToLayer("People"));
Now I want to know which of those collided People is the oldest one, I tried to use Linq (does that work also on iOS/Android?):
using System.Linq;
var itemWithMaxAge = hitColliders.Max(x => x.gameObject.GetComponent<MyCodeWithPublicAgeFloat>().age);
Debug.Log("Maximum Age:-" + itemWithMaxAge.ToString());
Why is itemWIthMaxAge a float? I got an error:
NullReferenceException: Object reference not set to an instance of an object
Caster+<>c.<MyCodeWithPublicFloat>b__13_0 (UnityEngine.Collider x) (at Assets/Scripts/MyCodeWithPublicFloat.cs:63)
System.Linq.Enumerable.Max[TSource] (System.Collections.Generic.IEnumerable`1[T] source, System.Func`2[T,TResult] selector) (at <351e49e2a5bf4fd6beabb458ce2255f3>:0)
Caster.caster (UnityEngine.Vector3 center, System.Single radius) (at Assets/Scripts/MyCodeWithPublicFloat.cs:63)
Caster.Update () (at Assets/Scripts/MyCodeWithPublicFloat.cs:49)