Beispiel #1
0
    private void Fill()
    {
        Collider[] hit = Physics.OverlapSphere(transform.position, MaxRange, _team.GetLayerMask())
                         .Where(x => Garrison.CanGarrison(x.transform.root.gameObject))
                         .GroupBy(x => x.transform.root).Select(x => x.First()).ToArray();
        float[] keys = hit.Select(x => Vector3.SqrMagnitude(x.transform.position - transform.position)).ToArray();
        Array.Sort(keys, hit);

        int toFill = Mathf.Min(hit.Length, Garrison.AvailableCount);

        for (int i = 0; i < toFill; i++)
        {
            Garrison.EnterGarrison(hit[i].transform.root.gameObject);
        }
    }