Answer the question
In order to leave comments, you need to log in
Why is the field null if I assign it?
Like there is this:
public class InventoryCell : MonoBehaviour, IPointerClickHandler
{
[SerializeField] private TMP_Text _amountText;
[SerializeField] private Image _iconField;
[HideInInspector] public UIInventory _uiInventory;
[HideInInspector] public Item _item;
public void OnPointerClick(PointerEventData eventData)
{
print(_uiInventory);
_uiInventory.RenderDescription(_item); // равно null
}
}
public class UIInventory : MonoBehaviour
{
[SerializeField] private InventoryCell _inventotyCell;
Inventory.Items.ForEach(item =>
{
var Amount = item.Amount;
while(true)
{
if(Amount >= item.MaxAmount)
{
var cell = Instantiate(_inventotyCell, _contaner);
cell._item = item;
cell._uiInventory = this;
cell.Render(item.MaxAmount, item.Image);
Amount -= item.MaxAmount;
}
else
{
var cell = Instantiate(_inventotyCell, _contaner);
cell._item = item;
cell.Render(Amount, item.Image);
Amount = 0;
}
if(Amount == 0)
{
break;
}
}
});
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question