private void CheckForInputs() { if (inputs.TriggerDown()) { if (m_ContactInteractables.Count != 0) { m_CurrentInteractable = GetNearestInteractable(); UseInteractable(); } } if (inputs.TriggerUp()) { DropInteractable(); } if (inputs.GripDown()) { handCollider.isTrigger = false; } if (inputs.GripUp()) { handCollider.isTrigger = true; } }
private void OnControllerColliderHit(ControllerColliderHit hit) { if (hit.gameObject.CompareTag("Interactable")) { IInteractables i = hit.gameObject.GetComponent <IInteractables>(); i.Action(this); } }
private void Interact() { interactionPosition = transform.position + localInteractionPositions[(int)facingDirection]; Collider2D otherCollider = Physics2D.OverlapBox(interactionPosition, interactionBoxSize, 0); IInteractables interactable = otherCollider?.gameObject.GetComponent <IInteractables>(); interactable?.Interact(); }
//Get list of all IInteractables in range and return the closest one private IInteractables GetNearestInteractable() { IInteractables nearest = null; float minDistance = float.MaxValue; float distance = 0.0f; foreach (IInteractables interactable in m_ContactInteractables) { distance = (interactable.GetTransform().position - transform.position).sqrMagnitude; if (distance < minDistance) { minDistance = distance; nearest = interactable; } } return(nearest); }
private void OnLookedAtInteractiveChanged(IInteractables NewLookedAtInteractable) { lookedAtInteractable = NewLookedAtInteractable; UpdateDisplayText(); }
private void OnLookedAtInteractiveChanged(IInteractables NewLookedAtInteractable) { lookedAtInteractable = NewLookedAtInteractable; }