using Reset.Items; using UnityEngine; using UnityEngine.InputSystem; namespace Reset.Units{ public class InteractionHandler : MonoBehaviour{ private PlayerEnvironmentManager envManager; private IInventory inventory; private EnvironmentObserver observer; void Awake(){ envManager = GetComponent(); inventory = GetComponent(); observer = envManager.FindObserverFromString("itemdrop"); observer.active = true; } public void InteractWith(GameObject target){ IInteractable interactable = target.GetComponent(); if (interactable == null) { Debug.LogError("This item cannot be interacted with, it has no Interactable interface"); return; } if (target.GetComponent()) { inventory.AddToInventory(target.GetComponent().item); } interactable.Interact(); // Don't do any actions that use the same button (hard set to Jump for now) Debug.Log($"Just collected the item, consuming the input @ {Time.time}."); GetComponent().SendInputBlock("Jump"); } void OnInteract(){ CheckForInteraction(); } private void CheckForInteraction(){ if (observer.active && observer.Evaluate(gameObject)) { InteractWith(observer.hit.transform.gameObject); } } } }