private void CheckInteraction() { RaycastHit hit; ray = mainCamera.ViewportPointToRay(Vector3.one / 2f); bool hasFoundValidItem = (Physics.Raycast(ray, out hit, interactibleDetectionDistance, layerMask)); if (hasFoundValidItem) { viewedItem = hit.transform.gameObject.GetComponent <Interactible> (); if (viewedItem) { if (!viewedItem.enabled || viewedItem.hasExternalTrigger) { viewedItem = null; } } hasFoundValidItem = (viewedItem && Vector3.Distance(hit.transform.position, playerCamera.transform.position) <= viewedItem.interactionDistance); if (hasFoundValidItem && Input.GetMouseButtonDown(0)) { activatedItem = viewedItem; activatedItem.TriggerInteraction(); } } interactionText.text = (hasFoundValidItem && !viewedItem.getForceRemoveLabel()) ? viewedItem.getPublicName() : ""; if (activatedItem && (!hasFoundValidItem || Input.GetMouseButtonUp(0))) { activatedItem.EndInteraction(); activatedItem = null; } }