first commit
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
using OTGIntegrated.Core;
|
||||
using OTGIntegrated.Inventory;
|
||||
using OTGIntegrated.Player;
|
||||
using UnityEngine;
|
||||
|
||||
namespace OTGIntegrated.Items
|
||||
{
|
||||
[RequireComponent(typeof(Collider))]
|
||||
public sealed class ItemPickup : MonoBehaviour, IInteractable
|
||||
{
|
||||
public ItemData itemData;
|
||||
[Min(1)] public int amount = 1;
|
||||
|
||||
public Transform InteractTransform => transform;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
Collider ownCollider = GetComponent<Collider>();
|
||||
ownCollider.isTrigger = true;
|
||||
}
|
||||
|
||||
public string GetPrompt()
|
||||
{
|
||||
string label = itemData != null ? itemData.displayName : "Предмет";
|
||||
return $"E — подобрать: {label}";
|
||||
}
|
||||
|
||||
public bool CanInteract(GameObject interactor)
|
||||
{
|
||||
return itemData != null && amount > 0;
|
||||
}
|
||||
|
||||
public void Interact(GameObject interactor)
|
||||
{
|
||||
OTGIntegrated.Inventory.Inventory inventory = GameManager.Instance != null
|
||||
? GameManager.Instance.inventory
|
||||
: interactor.GetComponentInChildren<OTGIntegrated.Inventory.Inventory>();
|
||||
if (inventory != null && inventory.AddItem(itemData, amount))
|
||||
{
|
||||
Destroy(gameObject);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user