Inventory = How to add items :) C-Sharp

Hi, im trying to create an inventory system to my game.
But i have problem with add items to my inventory. it is sad for me :frowning:

I’ve got:

In inventory.cs:

    float[,] plecak = new float[4,4]; // tablica, there are polish so ;) there is a two-dimensional array = plecak.

and simple GUI slots

        for(int i = 0; i < 4; i++)
        		{
        			for(int k = 0; k < 4; k++)
        			{
        			GUI.BeginGroup(new Rect(12,15,300,300));
        			GUI.Box (new Rect(5+(i*42),5+(k*42),40,40),":" +plecak[k,i]);	
        			GUI.EndGroup();
        			}		
        		}

On Item.cs i’ve go:

    private GameObject Gracz;
    private float odleglosc;
public Texture2D ikona;

	
void Start()
{
	Gracz = GameObject.FindWithTag("Player");
	
}

void Update()
{
	
}

void OnMouseDown()
{
odleglosc = (transform.position - Gracz.transform.position).sqrMagnitude;
	if(odleglosc <= 4f)
	{
		print("Jestes blisko.");
		//Here!!!!
		Destroy(gameObject);
	}	
	
}

Item on the ground have Tag = Item.

And, there where is “//Here!!!” i need some code to pick up items :frowning: could u help me? Please?

Are you trying to increment the corresponding plecak element when picking up some item? If so, you should specify in the item script which’s its element index - doing this with a public variable is the easiest way. Furthermore, the item must get a reference to the script inventory.cs - you could Find the object it’s attached to at Start. Supposing that this object is named “InventoryObject”:

public Texture2D ikona;
public int rowNum; // set the row number for this item
public int colNum; // set the column number for this item

private GameObject Gracz;
private float odleglosc;
private inventory invent;
 
void Start()
{
    Gracz = GameObject.FindWithTag("Player");
    // find the object named InventoryObject and get reference to the script inventory.cs
    invent = GameObject.Find("InventoryObject").GetComponent<inventory>();
}
 
void OnMouseDown()
{
    odleglosc = (transform.position - Gracz.transform.position).sqrMagnitude;
    if (odleglosc <= 4f)
    {
       print("Jestes blisko.");
       invent.plecak[colNum, rowNum] += 1; // increment element in the inventory
       Destroy(gameObject);
    }
}