public void InteractInput(InputAction.CallbackContext context) { if (currentInteractable != null && IsMovementInputAllowed() && currentInteractable.CanInteractWith()) { if (emitterInteract == null) { SetupAudioEmitters(); } emitterInteract.Play(); currentInteractable.OnInteract(); } }
private void StartInteracting(IInteractable interactable) { if (!interactable.CanInteractWith()) { return; } if (currentInteractable != null) { StopInteracting(); } currentInteractable = interactable; interactable.OnEnter(); if (interactable.GetInteractType() == E_InteractType.OnOverlap) { return; } OnItemInteractUI.SetActive(true); if (emitterOutline == null) { SetupAudioEmitters(); } emitterOutline.Play(); }
// Update is called once per frame void Update() { Collider[] interractables = Physics.OverlapSphere(transform.position, distance + 1, layers); // distance is offset such that objects dont get stuck at 0.01 opacity foreach (Collider c in interractables) { IInteractable interactable = c.GetComponent <IInteractable>(); if (interactable != null) { float actualDistance = Vector3.Distance(c.transform.position, transform.position); if (autoInteract && actualDistance < autoInteractDistance) { if (interactable.CanInteractWith(Interactor.Ivy)) { interactable.Interact(); } } float distanceRatio = actualDistance / distance; float opacity = 1 - distanceRatio; interactable.SetOpacity(opacity); } } }
void InteractWithNearest() { IInteractable nearest = GetNearestObjectWithinRange(); if (nearest != null) { if (nearest.CanInteractWith(interactorType)) { ; } { nearest.Interact(); } } }