Item Add - Inventory System

Hi, I have a problem with “Add Item” to inventory.
My code work but my item is not displayed on my inventory.
and i can’t fine solution, I am a beginer and all of the time i try understand how it works.
My code :

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Surowce : MonoBehaviour {

    public ItemDataBase database;

void OnTriggerEnter2D (Collider2D other)
    {
       
        if (other.gameObject.tag == "Player")
       
        {
            Inventory inventory = other.gameObject.GetComponent<Inventory> ();
            if (inventory)
           
            {
                inventory.AddItem(3);
                       
            }

        }
        Debug.Log ("Dodaje Deske");

        Destroy (gameObject);
    }
}

I will wait for yours answers and thanks for help

What’s the class Inventory, and how are you trying to display it?

What I’m gonna to do is:

  1. When the character comes into contact with the object:
    a) Object is deleted
    b) Item is Added to inventory
  2. Button " i " open my inventory where I can see what I have there.
    But the item is not added there, and this is my problem.

I don’t know if you ask about this:

"

using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class Inventory : MonoBehaviour
...
void Awake ()
        {
            database = GameObject.FindGameObjectWithTag ("Item DataBase").GetComponent<ItemDataBase>();
            for (int i = 0; i < (slotsX * slotsY); i++)
        {
            inventory.Add (new Item());
        }
...
public void AddItem(int id)
    {

        for (int i = 0; i < inventory.Count; i++)
        {
            if (inventory[i].itemName == null)
            {
                for (int j = 0; j < database.items.Count; j++)
                {
                    if (database.items[j].itemID == id)
                        inventory[i] = database.items[j];

                }
                break;
            }
    }
}

"

Problem is solved, but I got another one:

“NullReferenceException: Object reference not set to an instance of an object
Surowce.OnGUI () (at Assets/Skrypty/Surowce.cs:29)”

I don’t know what is wrong, some one have any Idea ?

Gracz sc = gameObject.GetComponent<Gracz>();
                sc._Ekwipunek.Pnie +=1;

There is probably no component of type “Gracz” attached to the GameObject.

I Did “public GameObject Gracz;” but problem is still the same.

Again problem is solved. The script I haved added to Object on scene, not to Player.
Thanks for help