Dymkens, спасибо ОГРОМНОЕ!!!!!!!!!!!!!! ++++
Вот какой скрипт получился и работает на ура!
Код
using UnityEngine;
using UnityEngine.UI;
public class ItemAdder : MonoBehaviour
{
[SerializeField] Button ButtonUse;
[SerializeField] GameObject ItemGO;
Inventory _inventory;
private void Start()
{
_inventory = GameObject.Find("[GM]").GetComponent<Inventory>();
}
private void OnTriggerStay(Collider other)
{
if (other.gameObject.tag.Equals("Item"))
{
ButtonUse.gameObject.SetActive(true);
ItemGO = other.gameObject;
}
}
private void OnTriggerExit(Collider other)
{
if (other.gameObject.tag.Equals("Item"))
{
ButtonUse.gameObject.SetActive(false);
ItemGO = null;
}
}
public void AddItem()
{
_inventory.AddItem(ItemGO.GetComponent<Item>());
ItemGO.SetActive(false);
ButtonUse.gameObject.SetActive(false);
ItemGO = null;
}
}