Answer the question
In order to leave comments, you need to log in
Why does the object not want to be deleted?
For some reason, it throws an error:
InvalidCastException: Specified cast is not valid.
Inventory.RenderItems () (at Assets/Scripts/Inventory.cs:17)
Inventory.OnEnable () (at Assets/Scripts/Inventory.cs:12)
Code:
public class Inventory : MonoBehaviour
{
[SerializeField] private List<Item> Items;
[SerializeField] private Transform _contaner;
[SerializeField] private InventoryCell _inventotyCell;
private void OnEnable()
{
RenderItems();
}
private void RenderItems()
{
foreach(GameObject child in _contaner)
{
Destroy(child);
}
Items.ForEach(item =>
{
var cell = Instantiate(_inventotyCell, _contaner);
cell.Render(item);
});
}
}
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