I am making a game, and I get the following error:
Object reference not set to an instance of an object.
This is my code:
public Image slotFirst;
bool isFirstEmpty = true;
public Image slotSecond;
bool isSecondEmpty = true;
public Image slotThird;
bool isThirdEmpty = true;
public Sprite keySprite;
public void GotKey() {
if (isFirstEmpty) {
slotFirst.sprite = keySprite;
isFirstEmpty = false;
}
else if (isSecondEmpty) {
slotSecond.sprite = keySprite;
isSecondEmpty = false;
}
else if (isThirdEmpty) {
slotThird.sprite = keySprite;
isThirdEmpty = false;
}
else {
Debug.Log("Inventory is full!");
}
}
Then I put objects in unity like this:
and then I get the error above.
What should I do to solve errors?
New contributor
박세익 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1