Esempio n. 1
0
    //Sets InteractionHandlers active/inactive as required
    private void DoInteractableCheck()
    {
        //TODO: Convoluted - revise this method
        var rayHits = Physics.SphereCastAll(m_Controller.GetCameraLocation(), 1f, m_Controller.GetLookDirection(), InteractDistance, InteractableLayerMask, QueryTriggerInteraction.Collide);

        rayHits = rayHits.Where(rh => rh.collider.gameObject.GetComponent <InteractionHandler>() != null).ToArray();

        if (rayHits.GetLength(0) == 0)
        {
            if (m_InteractHandler != null)
            {
                m_InteractHandler.Active = false;
                m_InteractHandler        = null;
            }
            InteractInputEnabled = false;
            return;
        }

        var closest      = GetClosestRayHit(rayHits);
        var interactable = closest.collider.gameObject.GetComponent <InteractionHandler>();

        if (interactable == null)
        {
            if (m_InteractHandler != null)
            {
                m_InteractHandler.Active = false;
                m_InteractHandler        = null;
            }
            InteractInputEnabled = false;
        }
        else
        {
            InteractInputEnabled     = true;
            m_InteractHandler        = interactable;
            m_InteractHandler.Active = true;
        }
    }