Hey all,
I’m new to programming and making games and learning as I go.
Currently stuck on a bug with inventory and showing items in the inventory when picked up.
I have found the lines causing the issue which are 17, 18 and 26. I have them currently commented out.
If I run the game and pick up the items, they go into my inventory and shows the icon I set and how many I picked up. But I get:
NullReferenceException: Object reference not set to an instance of an object
Slot_UI.SetEmpty () (at Assets/Scripts/Scripts/Slot_UI.cs:26)
Inventory_UI.Setup () (at Assets/Scripts/Scripts/Inventory_UI.cs:53)
Inventory_UI.ToggleInventory () (at Assets/Scripts/Scripts/Inventory_UI.cs:33)
Inventory_UI.Update () (at Assets/Scripts/Scripts/Inventory_UI.cs:23)
If I run the game and open my inventory before picking up anything and close it and pick up something and then open my inventory, it doesn’t show the icon or chnage the value of how many were picked up. I get this error:
NullReferenceException: Object reference not set to an instance of an object
Slot_UI.SetItem (Inventory+Slot slot) (at Assets/Scripts/Scripts/Slot_UI.cs:17)
Inventory_UI.Setup () (at Assets/Scripts/Scripts/Inventory_UI.cs:49)
Inventory_UI.ToggleInventory () (at Assets/Scripts/Scripts/Inventory_UI.cs:33)
Inventory_UI.Update () (at Assets/Scripts/Scripts/Inventory_UI.cs:23)
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class Slot_UI : MonoBehaviour
{
public Image itemIcon;
public TextMeshProUGUI quantityText;
public void SetItem(Inventory.Slot slot)
{
if(slot != null)
{
// itemIcon.sprite = slot.icon;
// itemIcon.color = new Color(1, 1, 1, 1);
quantityText.text = slot.count.ToString();
}
}
public void SetEmpty()
{
itemIcon = null;
// itemIcon.color = new Color(1, 1, 1, 0);
quantityText.text = "";
}
}
Has anyone worked on sometime like this before and can see the issue?