// Update is called once per frame void Update() { Debug.DrawRay(transform.position, transform.TransformDirection(Vector3.forward) * 100, Color.yellow); if (Input.GetMouseButtonDown(RMB)) { Ray ray = PlayerCamera.ScreenPointToRay(Input.mousePosition); if (Physics.Raycast(ray, out raycastHit, ClickDistance, layerMask)) { if (raycastHit.transform) { //Debug.Log(raycastHit.transform.gameObject); IUsable Clickable = raycastHit.transform.GetComponent <IUsable>(); //Debug.Log(Clickable); if (Clickable != null) { if (typeof(IInteractionable).IsAssignableFrom(Clickable.GetType())) { //Debug.Log("Interactionable"); ((IInteractionable)Clickable).PerformInteraction(); } else { //Debug.Log("Usable"); Clickable.PerformAction(); } } } } } }
private void Update() { Ray ray = Camera.main.ViewportPointToRay(m_rayOrigin); if (Physics.Raycast(ray, out hit, rayLength)) { m_grabbableObject = hit.collider.gameObject; } if (Input.GetMouseButtonDown(1)) { if (!m_hasGrabbed) { if (m_grabbableObject?.GetComponent <Tool>()) { GrabObject(m_grabbableObject); } } else { if (m_grabbableObject) { ReleaseObject(); } } } if (Input.GetMouseButtonDown(0)) { if (m_hasGrabbed) { m_toolObject?.PerformAction(m_grabbableObject); } if (m_grabbableObject?.GetComponent <MonoBehaviour>() is IOpenable) { m_grabbableObject?.GetComponent <IOpenable>().Open(); } } }