Answer the question
In order to leave comments, you need to log in
How to make an instance of a class not be a reference, but rather a value?
Tipo scriptable object and class is the same reference type. And there is a list of items and there is in order to add them to the ui and after creating the object, the Render method is called and there the Item parameter and there is a customItem field supposedly should inherit almost everything from item, but besides the customItem variables, it also changes the item variables.
If you don't understand, here is the code:
Inventory.Items.ForEach(item =>
{
var Amount = item.Amount;
Item customItem = item;
while(true)
{
if(Amount >= item.MaxAmount)
{
customItem.Amount = item.MaxAmount;
Amount -= item.MaxAmount;
var cell = Instantiate(_inventotyCell, _contaner);
cell.Render(customItem);//new Item() { Amount = item.MaxAmount, Image = item.Image });
}
else
{
customItem.Amount = Amount;
Amount = 0;
var cell = Instantiate(_inventotyCell, _contaner);
cell.Render(customItem);//new Item() { Amount = item.MaxAmount, Image = item.Image });
}
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