private void HandleInteraction() { m_PreviousInteractionCube = m_InteractionCube; if (m_Camera) { m_InteractionCube = null; RaycastHit hit; int x = Screen.width / 2; int y = Screen.height / 2; var point = m_Camera.ScreenToWorldPoint(new Vector3(x, y, 1.0f)); var direction = (point - m_Camera.transform.position).normalized; //Debug.DrawLine(m_Camera.transform.position, m_Camera.transform.position + direction * m_InteractionDist, Color.red, 100); if (Physics.Raycast(m_Camera.transform.position, direction, out hit, m_InteractionDist, LayerMask.GetMask("Trigger") | LayerMask.GetMask("Level") | LayerMask.GetMask("Interaction"))) { m_InteractionCube = hit.collider.gameObject.GetComponent <IInteractionCube>(); if (m_InteractionCube != m_PreviousInteractionCube && m_PreviousInteractionCube != null) { m_PreviousInteractionCube.EndInteraction(); } if (m_InteractionCube != null && m_InteractionPoint) { m_InteractionPoint.OnFocus(); } } else { if (m_IsInteracting && m_PreviousInteractionCube != null) { m_PreviousInteractionCube.EndInteraction(); } m_IsInteracting = false; if (m_InteractionPoint) { m_InteractionPoint.OnLeaveFocus(); } } } if (Input.GetMouseButtonDown(0) && m_InteractionCube != null) { m_InteractionCube.StartInteraction(this); m_IsInteracting = true; } if (Input.GetMouseButtonUp(0) && m_InteractionCube != null) { m_InteractionCube.EndInteraction(); m_IsInteracting = false; } }