S
S
Serdarchik Chirik2020-12-18 18:43:00
Unity
Serdarchik Chirik, 2020-12-18 18:43:00

NullReferenceException?

NullReferenceException: Object reference not set to an instance of an object
PickUp.OnTriggerEnter2D (UnityEngine.Collider2D other) (at Assets/Scripts/Inventory/PickUp.cs:25)

public class PickUp : MonoBehaviour
{

    private Inventory inventory;
    public GameObject slotButton;

    void Start()
    {
        inventory = GameObject.FindGameObjectWithTag("Player").GetComponent<Inventory>();
    }

    private void OnTriggerEnter2D(Collider2D other)
    {
        if (other.CompareTag("Player"))
        {
            for (int i = 0; i < inventory.slots.Length ; i++)
            {
                if (inventory.isFull[i] == false)
                {
                    inventory.isFull[i] = true;
                    Instantiate(slotButton, inventory.slots[i].transform);
                    Destroy(gameObject);
                    break;
                }
            }
        }
    }
}

Sorry for the stupidity, maybe, but I just started working with the unit and this error is incomprehensible to me (Please help.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question