void Update() { int InteractablesMask = 1 << InteractablesLayer; int ChatbotMask = 1 << ChatbotLayer; Ray forwardRay = new Ray(transform.position, transform.forward); RaycastHit hit; if (Physics.Raycast(forwardRay, out hit, InteractionDistance, InteractablesMask)) { IInteractableBase interactable = Utils.GetComponentAcrossGameobject <IInteractableBase>(hit.collider.gameObject); bool interact = interactable.OnHover(transform); if (interact) { ShowInteractUI(true); } if (Input.GetMouseButtonDown(0) && !PauseMenu.isPaused) { interactable.OnClick(); } } else if (Input.GetKeyDown(KeyCode.Escape) && openChatbotController != null) { openChatbotController.CloseChatbot(); openChatbotController = null; } else if (Physics.Raycast(forwardRay, out hit, InteractionDistance, ChatbotMask)) { ShowInteractUI(true); if (Input.GetMouseButtonDown(0) && openChatbotController == null) { openChatbotController = hit.collider.GetComponent <ChatbotController>(); openChatbotController.OpenChatbot(); } } else { ShowInteractUI(false); } }
//################################################################### // Jose: // Change so the current selection points to the itementity script // and probably put the selection code in there void IndicateSelections() { // generic approach to deselect // extra steps cause Unity if (interactingBase != null && !interactingBase.Equals(null)) { interactingBase.OnDeselect(player); } if (interactingAlt != null && !interactingAlt.Equals(null)) { interactingAlt.OnDeselectAlt(player); } // search all colliders for an iinteractable interface GetInteractionBox(out var point1, out var point2, out var radius); var hitColliders = Physics.OverlapCapsule(point1, point2, radius, interactionLayerMask); IInteractableBase basehit = null; float basedis = float.MaxValue; int basepri = int.MaxValue - 1; IInteractableAlt althit = null; float altdis = float.MaxValue; int altpri = int.MaxValue - 1; foreach (Collider hitCol in hitColliders) { // moved interactable check here var interact = hitCol.transform.GetComponentInParent <IInteractable>(); if (interact != null) { var basetemp = interact as IInteractableBase; if (basetemp != null) { var pri = basetemp.IsInteractable(player); var sqrdis = SqrMagnitudeXZ(transform.position, hitCol.transform.position); if (pri > basepri) { goto alt; // higher priority. don't try } else if (pri == basepri && sqrdis >= basedis) { goto alt; // same priority, check distance } basedis = sqrdis; basepri = pri; basehit = basetemp; } alt :; var alttemp = interact as IInteractableAlt; if (alttemp != null) { var pri = alttemp.IsInteractableAlt(player); var sqrdis = SqrMagnitudeXZ(transform.position, hitCol.transform.position);; if (pri > altpri) { goto done; // higher priority. don't try } else if (pri == altpri && sqrdis >= altdis) { goto done; // same priority, check distance } altdis = sqrdis; altpri = pri; althit = alttemp; } done :; } } interactingBase = basehit; interactingAlt = althit; // generic approach to select interactingBase?.OnSelect(player); interactingAlt?.OnSelectAlt(player); }