How to store gameobjects to create an inventory.

Hello, I want to create an inventory system but I dont know how to start, I cant seem to figure out how should I store the gameobjects the player collects and how to stack them if the item is already there. I dont need the code for full inventory system, just some hints to put me in the right track.

This is an example of an item I created:

using UnityEngine;
using System.Collections;

public class Potion : MonoBehaviour {
	public int PotionValue;
	public AudioClip[] PotionSounds;
	public int Cantidad = 0;
	// Use this for initialization
	
	void Start () {
	
	}
public void AddCantidad(int exCantidad){
		Cantidad += exCantidad;
	}
	
public void use(){
	GameObject Player = GameObject.FindGameObjectWithTag("Player");
	Player.SendMessage("AddjustCurrentHealth", PotionValue);
	audio.PlayOneShot(PotionSounds[(Random.Range(0,PotionSounds.Length))]);
	Destroy(gameObject);
	}
}

Thanks a lot

I am not an expert, but i think you can store the gameObjects in your player prefs list and then make sure that when there is 1 of the gameObject, and you collect another you will have 2 of them. I think you can do this by saying that if you collect an item, it should set the value of the item to +1. Not an expert though, this is just a guess!

I will be making a game that requires an inventory but i haven’t tackled it yet. But the way i thought about going around in doing it is to that the inventory will be an array that holds an int (the number of times i found that item) and a string (item’s name.)
The game would spawn that item in the screen when the player would click on the GUITexture.
I’d have an empty gameobject as a child in the player’s hand, and the game would take that transformation as the point to spawn the game object that was in the inventory.

There would be a few ways to do this, but I would do something like this.
Take a look the tutorial on Lists I think you might find it helpful. I probably wrote too much code, but sometimes it’s easier to understand than paragraphs of explanation.

IItem.cs

// Interface, containing only signature (design), not implementation
interface IItem { 
  // classes that implement Item should define this method
  void UseItem();
}

Potion.cs

// Implements the Item interface. Attach this to potion gameobject.
public class Potion : MonoBehaviour, IItem { 
  public AudioClip[] PotionSounds;
  public int PotionValue;
    
  public void UseItem() {
    GameObject Player = GameObject.FindGameObjectWithTag("Player");
    Player.SendMessage("AddjustCurrentHealth", PotionValue);
    audio.PlayOneShot(PotionSounds[(Random.Range(0, PotionSounds.Length))]);
    Destroy(gameObject);
  }
}

InventoryManager.cs

// This behaviour script would be attached to the player
public class InventoryManager : MonoBehaviour {
  // stores items picked up
  private List<IItem> itemsInInventory = new List<IItem>();
    
  void Update() {
    // check for use input to use item here, or in OnGUI, and call Use()   
  }
    
  void OnCollisionEnter(Collision col) {
    if (col.gameObject.tag == "Potion") {
      // We cast to IItem to match our list type. 
      // We can do this because Potion implements IItem.
      // This means we could store different types of items in the list, 
      // as long as they implement IItem.
      itemsInInventory.Add((IItem)col.gameObject.GetComponent<Potion>()); // adds new item to end of list
    }
  }
    
  void Use() {
    if (itemsInInventory.Count > 0) {
      // execute UseItem method of first item in list
      itemsInInventory[0].UseItem(); 
      // remove item from list since it has been used
      itemsInInventory.RemoveAt(0); 
    }
  }
}