void Interact() { hitCooldown.Timeout(); interactCooldown.Timeout(); Interactable target = hitCooldown.IsStarted ? null : interaction.GetClosest(); bool canInteract = false; if (target != null) { canInteract = target.CanBeInteractedWith(); } for (int i = 0; i < interaction.targets.Count; i++) { Interactable t = interaction.targets[i]; bool same = target == null ? false : t == target; t.SetHighlighted(same && canInteract); } if (!canInteract || interactCooldown.IsStarted) { return; } IItem item = target as IItem; bool wasGrabbed = item?.IsGrabbed ?? false; Factory factory = target as Factory; bool wantInteract = inputInteract.PosHolded; if (wasGrabbed || factory != null) { wantInteract = inputInteract.PosPressed; } if (!wantInteract) { return; } if (target.Interact()) { interactCooldown.Start(); if (item != null && !wasGrabbed) { grabbed.Add(item); item.Interactable.onDestroy += OnGrabbedDestroyed; } Deposit deposit = target as Deposit; if (deposit != null) { hitCooldown.Start(); } } }