示例#1
0
    void FindItemForSelection()
    {
        var hitColliders = Physics2D.OverlapCircleAll(transform.position, 0.32f, activeObjects);

        GameObject closest = null;

        foreach (var hitCollider in hitColliders)
        {
            if (closest == null)
            {
                closest = hitCollider.gameObject;
            }
            else if (Vector3.Distance(closest.transform.position, transform.position) > Vector3.Distance(hitCollider.transform.position, transform.position))
            {
                closest = hitCollider.gameObject;
            }
        }

        if (closest != null)
        {
            SelectItem(closest.GetComponent <ActiveObject>());
        }
        else if (highlighted != null)
        {
            highlighted.Unhighlight();
            highlighted = null;
        }
    }