2

Someone here is a gallows. I have the following problem. I have two classes. .a class ListPainel. and the class Items Requirements.

in class ListPainel I have the following:

[System.Serializable]
public class Item
{
public GameObject slotPrafab;
public int numeroDeItensDisp;
public int numeroDeItensTotal;
}
public List<Item> itemList;

etc etc...

and in the class RequirementsItems I have the following: Only public variables so that I can change in the inspector unity.

public Sprite imageNewItem;
public Image imageItem;
public Text req;
public string barra;
public int numberReqDisp;
public int numberReqTotal;
public static Item painel;

etc etc...

and I need the value of the variable / numberReqDisp; be = number of items; of the class listPainel ... so I'll delude this way:

numberReqDisp = painel.numeroDeItensDisp;

and what happens. in my unity. the values do not change. and it gives error "Object reference not set to an instance of an object"

.. and to make clear the class items required is attached to a prefab.

1 Answers1

1

"Object reference not set to an instance of an object" means that it is not initialized. You can do it like that. But also don't forget to assign the values of painel. Like that:

public static Item painel = new Item();
painel.slotPrafab = ...

Or define a constructor for doing so.

QuesterDesura
  • 385
  • 2
  • 18