private void Update() { _ray = _mainCamera.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f)); if (Physics.Raycast(_ray, out _hit, _maxRayDistance, _interactableLayer)) { if (Input.GetKeyDown(KeyCode.E)) { _hit.collider.GetComponent <IInteractable>().Interact(); _isReadyToInteract = false; OnInteractionUnavailable?.Invoke(); } else if (!_isReadyToInteract) { _isReadyToInteract = true; OnInteractionAvailable?.Invoke(); } } else { if (_isReadyToInteract) { _isReadyToInteract = false; OnInteractionUnavailable?.Invoke(); } } }
private void OnTriggerExit(Collider other) { playerInRange = false; OnInteractionUnavailable?.Invoke(interactable.interactionType); }
public void TriggerInteraction() { if (!active) { Debug.LogWarning(name + ": this trigger is not active. Not Triggering interaction"); return; } if (interactionType != InteractionTriggerTypes.OnInput) { return; } interactable.Interact(); if (disableAfterTrigger) { active = false; OnInteractionUnavailable?.Invoke(interactable.interactionType); } }