예제 #1
0
    void CheckForInteractable()
    {
        Ray        _ray = new Ray(m_cam.transform.position, m_cam.transform.forward);
        RaycastHit _hitInfo;
        bool       _hitSomething = Physics.SphereCast(_ray, raySphereRadius, out _hitInfo, rayDistance, interactableLayer);

        // debug
        Debug.DrawRay(_ray.origin, _ray.direction, _hitSomething?Color.green:Color.red);
        // -----

        if (_hitSomething)
        {
            InteractableBase _interactable = _hitInfo.transform.GetComponent <InteractableBase>();
            if (_interactable != null && _interactable.IsInteractable)
            {
                if (interactionData.IsEmpty() || (!interactionData.IsSameInteractable(_interactable)))
                {
                    interactionData.Interactable = _interactable;
                    uiPanel.SetToolTip(_interactable.TooltipMessage);
                }
            }
        }
        else
        {
            uiPanel.ResetUI();
            interactionData.ResetData();
        }
    }
예제 #2
0
    void CheckForInteractable()
    {
        //Ray to the direction : Front of player.
        m_ray = new Ray(rayPositionOffset.position, gameObject.transform.forward);

        RaycastHit _hitInfo;

        // m_hitSomething = Physics.SphereCast(m_ray, raySphereRadius, out _hitInfo, rayDistance, interactableLayer);
        m_hitSomething = Physics.Raycast(m_ray, out _hitInfo, rayDistance, interactableLayer);


        if (m_hitSomething)
        {
            InteractableBase _interactable = _hitInfo.transform.GetComponent <InteractableBase>();

            if (_interactable == null)
            {
                _interactable = _hitInfo.transform.GetComponentInChildren <InteractableBase>();
            }

            if (_interactable != null)
            {
                //Fill Interaction Data
                if (interactionData.IsEmpty())
                {
                    interactionData.Interactable = _interactable;
                }
                else
                {
                    if (!interactionData.IsSameInteractable(_interactable))
                    {
                        interactionData.Interactable.StopParticles();
                        interactionData.Interactable = _interactable;
                    }
                }

                interactionData.Interactable.PlayParticles();
            }
        }
        else
        {
            if (interactionData.Interactable)
            {
                interactionData.Interactable.StopParticles();
            }

            //Reset interaction Data
            interactionData.ResetData();
        }
    }