Exemplo n.º 1
0
    public virtual GameObject ChoiceOfTarget(Collider2D[] colliders, IComparer comparer, float epsilon)
    {
        var currentDistance = epsilon;
        var target          = -1;

        for (var i = 0; i < colliders.Length; i++)
        {
            if (colliders[i].tag != "Zombie" && colliders[i].tag != "Bullet")
            {
                var distance = Vector3.Distance(transform.position, colliders[i].transform.position);
                if (comparer.CheckDistance(currentDistance, distance))
                {
                    target          = i;
                    currentDistance = distance;
                }
            }
        }


        if (target == -1)
        {
            return(null);
        }

        return(colliders[target].gameObject);
    }