// Update is called once per frame void Update() { if (controller == null) { Debug.Log("Controller not initialized"); return; } if (controller.GetPressDown(gripButton) || controller.GetPressDown(triggerButton)) { // Find the closest item to the hand in case there are multiple and interact with it float minDistance = float.MaxValue; float distance; foreach (InteractableBase item in objectsHoveringOver) { distance = (item.transform.position - transform.position).sqrMagnitude; if (distance < minDistance) { minDistance = distance; closestItem = item; } } interactingItem = closestItem; closestItem = null; if (interactingItem) { // Begin Interaction should already end interaction from previous if (controller.GetPressDown(gripButton)) { interactingItem.OnGripPressDown(this); } if (controller.GetPressDown(triggerButton)) { interactingItem.OnTriggerPressDown(this); } } } if (controller.GetPressUp(gripButton) && interactingItem != null) { //interactingItem.EndInteraction(this); interactingItem.OnGripPressUp(this); } if (controller.GetPressDown(triggerButton) && interactingItem != null) { interactingItem.OnTriggerPressUp(this); } }