Не передается метод класса
Всем добрый день, столкнулся с такой проблемой, в коде ниже. Я передаю метод из компонента объекта, с которым столкнулся, хотя в коде ошибок не выводится, метод просто не передается. Если же передать метод из этого же скрипта, то все нормально работает
public void AddInventory(Collider other)
{
if (other.gameObject.GetComponent<ItemObject>())
{
var item = other.gameObject.GetComponent<ItemObject>();
var check = invObjs.FindIndex(takeItem => takeItem.nameItem == item.nameItem);
if (check == -1)
{
InventoryObject invObj = new InventoryObject();
invObj.count = item.count;
invObj.sprite = item.sprite;
invObj.nameItem = item.nameItem;
invObj.price = item.price;
invObj.prefab = item.prefab;
invObj.button = Instantiate(buttonPrefab, content.transform);
Image sprite = invObj.button.GetComponentsInChildren<Image>()[1];
Text countText = invObj.button.GetComponentInChildren<Text>();
countText.text = item.count.ToString();
sprite.sprite = invObj.sprite;
Button button = invObj.button.GetComponentInChildren<Button>();
if (item is Sword)
{
item = (Sword)item;
button.onClick.AddListener(item.Use);
}
else if (item is Potion)
{
item = (Potion)item;
button.onClick.AddListener(item.Use);
}
else if (item is ItemObject)
{
button.onClick.AddListener(item.Use);
}
invObjs.Add(invObj);
Destroy(other.gameObject);
Debug.Log("Удалили");
}
else
{
invObjs[check].count += item.count;
invObjs[check].button.GetComponentInChildren<Text>().text = invObjs[check].count.ToString();
Destroy(other.gameObject);
}
}
else
{
Debug.Log("Не вышло");
}
}