Пример #1
0
    /// <summary>
    /// Check for colliders that are keyboard keys.
    /// </summary>
    public void CheckForKeyCollision()
    {
        if (!m_Open)
        {
            return;
        }

        if (m_CurrentButton != null)
        {
            m_CurrentButton.OnTriggerStay(m_BulbCollider);
        }

        var            shortestDistance = Mathf.Infinity;
        KeyboardButton hitKey           = null;

        Collider[] hitColliders = Physics.OverlapSphere(m_Bulb.position, m_BulbRadius);
        foreach (var col in hitColliders)
        {
            var key = col.GetComponentInParent <KeyboardButton>();
            if (key != null)
            {
                var newDist = Vector3.Distance(m_Bulb.position, key.transform.position);
                if (newDist < shortestDistance)
                {
                    hitKey = key;
                }
            }
        }

        if (m_CurrentButton != hitKey)
        {
            if (m_CurrentButton != null)
            {
                m_CurrentButton.OnTriggerExit(m_BulbCollider);
            }

            m_CurrentButton = hitKey;

            if (m_CurrentButton != null)
            {
                m_CurrentButton.OnTriggerEnter(m_BulbCollider);
            }
        }
    }