Stackable Inventory Items?

Hello everyone, I’ve been having a though time figuring this out so any assistance would be appreciated.

I’m attempting to get my items to stack within the inventory which I have got working, However It seems that each stack has the same amount as one another(For example, If I have 3 stacks of health potions with 20 in each and if I take 10 away from stack ‘1’ then 10 will be taken from stack ‘2’ and ‘3’) It seems that each stack carries the same value? How would I go about getting each stack to have its very own quantity?

(I apologize if this is a newbie question, I’m still learning)

Below I will provide my Item Class as well as my “Add Item” function, If you need more of my code just ask but I think what im asking should be handled in here.

Here is my Add Item Function:

void AddItem(int id, int amount)
	{
		for(int i = 0; i < inventory.Count; i++)
		{
			if(inventory<em>.itemID == id && inventory_.itemCurStack < inventory*.itemMaxStack)*_</em>

* {*
* for(int j = 0; j < database.items.Count; j++)*
* {*
* if(database.items[j].itemID != 1 && database.items[j].itemID == id && database.items[j].stackable)*
* {*
if(inventory_.itemCurStack < inventory*.itemMaxStack)
{
int cnt = 0;
cnt = inventory.itemMaxStack - inventory.itemCurStack;
if(amount > cnt)
{
inventory.itemCurStack += cnt;
amount -= cnt;
AddItem (id, amount);
}else*

inventory*.itemCurStack += amount;
}*_

* }*
* }*
* break;*
_ }else if(inventory*.itemName == null)
{
for(int j = 0; j < database.items.Count; j++)
{
if(database.items[j].itemID != 1 && database.items[j].itemID == id)
{
inventory = database.items[j];
inventory.itemCurStack ++;
amount --;
if(amount > 0)
{
AddItem (id, amount);
}
}else if(database.items[j].itemID == 1 && database.items[j].itemCurStack < database.items[j].itemMaxStack)
//Add Currency’s*

* database.items[j].itemCurStack += amount;
}
break;
}
}
}*

Here is my Item Class:
using UnityEngine;
using System.Collections;_

[System.Serializable]
public class Item
{
* public string itemName;*
* public int itemID;*
* public string itemDescr;*
* public Texture2D itemIcon;*
* public ItemType itemType;*
* public ItemRarity itemRarity;*
* public bool sellable;*
* public bool stackable;*
* public int itemCurStack;*
* public int itemMaxStack;*
* public int itemCost;*
* public int itemDamage;*
* public int itemSpeed;*

* public enum ItemType*
* {*
* Helmet,*
* Chest,*
* Legs,*
* Boots,*
* Ring,*
* Neckless,*
* Weapon1H,*
* Weapon2H,*
* Shield,*
* Resource,*
* Consumable,*
* Quest,*
* Festival*
* }*

* public enum ItemRarity*
* {*
* Common,*
* Uncommon,*
* Rare,*
* Ancient*
* }*

* public Item(string name, int id, string descr, ItemType type, ItemRarity rarity, bool canSell, bool canStack, int curStack, int maxStack, int cost, int damage, int speed)*
* {*
* itemName = name;*
* itemID = id;*
* itemDescr = descr;*
* itemIcon = Resources.Load (“Item Icons/” + name);*
* itemType = type;*
* itemRarity = rarity;*
* sellable = canSell;*
* stackable = canStack;*
* itemCurStack = curStack;*
* itemMaxStack = maxStack;*
* itemCost = cost;*
* itemDamage = damage;*
* itemSpeed = speed;*
* }*

* public Item()*
* {*

* }*
}

I did something pretty similar for a school project a few months back. off the top of my head, I had to make a loop that is dependent on the added item’s stack size. Something like:

if (currentItem is stackable) {
	for (every inventoryItem) {
		if (currentItem is of same type as inventoryItem) {
			for (every currentItem's currentStack) {
				if (inventoryItem's currentStack is less than its maxStack) {
					currentItem.currentStack--
					inventoryItem.currentStack++
					}
				}
			}
		}
	}
	
if (currentItem's currentStack > 0) {
	Add currentItem as a new Item in inventory
	}
else {
	Destroy currentItem
	}

Basically, once it finds an item of the same type, it initiates a loop that checks if the inventoryItem has space in the stack and then adds 1, repeat. Once inventoryItem has reached maxStack, it will move on to the next item. Once currentItem’s stack is 0, it will stop adding. Once the whole loop is finished and currentItem’s stack is greater than 0, it adds currentItem as a new entry in the Inventory. Else, the currentItem is destroyed.