void CheckForInteractable() { Ray _ray = new Ray(Camera.main.transform.position, m_cam.transform.forward); RaycastHit _hitInfo; bool _hitSomething = Physics.SphereCast(_ray, raySphereRadius, out _hitInfo, rayDistance, interactableLayer); if (_hitSomething) { InteractableBase _interactable = _hitInfo.transform.GetComponent <InteractableBase>(); if (_interactable != null) { if (interactionData.IsEmpty() || !interactionData.IsSameInteractable(_interactable)) { interactionData.Interactable = _interactable; } uiPanel.SetToolTip(_interactable.ToolTipMessage); } } else { uiPanel.ResetUI(); interactionData.ResetData(); } Debug.DrawRay(_ray.origin, _ray.direction * rayDistance, _hitSomething ? Color.green:Color.red); }
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(); } }