コード例 #1
0
    void Start()
    {
        GameObject obj = GameObject.FindGameObjectWithTag("Player");

        m_distanceComparer.SetTarget(obj.transform);

        m_sphereList.AddRange(GetComponentsInChildren <Transform>(true));
        m_sphereList.Sort(m_distanceComparer);

        for (int i = 0; i < m_sphereList.Count; ++i)
        {
            Debug.Log(m_sphereList[i].position.magnitude);
        }
    }
コード例 #2
0
    void Awake()
    {
        GameObject obj = GameObject.FindGameObjectWithTag("Player");

        distanceComparer.SetTarget(obj.transform);

        sphereList.AddRange(GetComponentsInChildren <Transform>(true));
        sphereList.Sort(distanceComparer);       // Comparer를 사용하는 부분

        for (int i = 0; i < sphereList.Count; i++)
        {
            Debug.Log(sphereList[i].position.magnitude);
        }
    }
コード例 #3
0
    void BeginAbility()
    {
        Collider[] hits = Physics.OverlapSphere(player.position, Mathf.Infinity);
        foreach (Collider hit in hits)
        {
            if (hit.tag == Globals.INTERACTABLE_ITEM)
            {
                // Set items to objects hit
                items = GameObject.FindGameObjectsWithTag(hit.tag);
                DistanceComparer dComp = new DistanceComparer();
                dComp.SetTarget(player.gameObject);
                // Sort objects based on distance from player
                System.Array.Sort(items, dComp);
            }
        }

        // TODO: Possibly fix this to make it more dynamic...work with less than 4 objects
        if (items.Length > 0)
        {
            StartCoroutine("SpawnOrbitHolders");
        }
    }