void Update() { // Cast a ray to look for some object Physics.Raycast(cam.transform.position, cam.transform.forward, out hit, interactRange); // Check if some object was hit if (hit.transform) { // Check if hit object is interactive hitInteract = hit.transform.GetComponent <IInteractive>(); if (hitInteract != null) { actions = hitInteract.GetHitActions(gameObject, carryObject); if (actions != null) { // Show possible actions in the UI ShowActionsUI(actions); // Execute player action on the hitInteract (if any) bool actionExecuted = HandleHitActions(hitInteract, actions); if (actionExecuted) { return; } } } } // Check if carry object is interactive if (carryObject != null) { IInteractive carryInteract = carryObject.GetComponent <IInteractive>(); if (carryInteract != null) { actions = carryInteract.GetCarryActions(gameObject); if (actions != null) { // Show possible actions in the UI ShowActionsUI(actions); // Execute player action on the carryInteract (if any) HandleCarryActions(carryInteract, actions); } } } }