melee weapon now spawns in hand melee substate cleaned up to work with above added new playerinventory script on player added new playeranimation script on player changed inventory to IInventory animations tweaked to avoid a lockout
49 lines
1.6 KiB
C#
49 lines
1.6 KiB
C#
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<PlayerEnvironmentManager>();
|
|
inventory = GetComponent<IInventory>();
|
|
|
|
observer = envManager.FindObserverFromString("itemdrop");
|
|
|
|
observer.active = true;
|
|
}
|
|
|
|
public void InteractWith(GameObject target){
|
|
IInteractable interactable = target.GetComponent<IInteractable>();
|
|
|
|
if (interactable == null) {
|
|
Debug.LogError("This item cannot be interacted with, it has no Interactable interface");
|
|
return;
|
|
}
|
|
|
|
if (target.GetComponent<ItemDrop>()) {
|
|
inventory.AddToInventory(target.GetComponent<ItemDrop>().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<PlayerControls>().SendInputBlock("Jump");
|
|
}
|
|
|
|
void OnInteract(){
|
|
CheckForInteraction();
|
|
}
|
|
|
|
private void CheckForInteraction(){
|
|
if (observer.active && observer.Evaluate(gameObject)) {
|
|
InteractWith(observer.hit.transform.gameObject);
|
|
}
|
|
}
|
|
}
|
|
} |