Inventorysystem newbie help

Greetings World, I have a little problem and I mean not my bad english :slight_smile: excuse me… I hope everbody understand me…

I have to make this tutorial::: https://www.youtube.com/watch?v=f4Op-UdvdK0

but the last part 9 is other then the part… but that is not really the Problem…

My Question :

	void DrawInventory()
	{
		Event e = Event.current;

		int i = 0;

				
		for (int y = 0; y < slotsY; y++) 
		{
			for (int x = 0; x < slotsX; x++) 
			{
				Rect slotRect = new Rect (x * 60, y * 60,50,50);
				GUI.Box (slotRect, "", skin.GetStyle("Slot"));
				slots[i] = inventory[i];
				Item item = slots [i];
				if(slots[i].itemName != null)
				{
					GUI.DrawTexture(slotRect, slots[i].itemIcon);
					if(slotRect.Contains(e.mousePosition))
					{
						tooltip = CreateTooltip(slots[i]);
						showTooltip = true;
						if(e.button == 0  e.type == EventType.mouseDrag  !draggingItem)
						{
							draggingItem = true;
							prevIndex = i;
							draggedItem = slots[i];
							inventory[i] = new Item();

						}
						if(e.type == EventType.mouseUp  draggingItem)
						{
							inventory[prevIndex] = inventory[i];
							inventory[i] = draggedItem;
							draggingItem = false;
							draggedItem = null;
						}
					
					
					}
				}
				else { 
					if(slotRect.Contains(e.mousePosition))
					{
						if(e.type == EventType.mouseUp  draggingItem)
						{
							inventory[i] = draggedItem;
							draggingItem = false;
							draggedItem = null;	
						}
					}
				}
				if (e.isMouse  e.type == EventType.mouseDown  e.button == 1) 
				{
					
					if(item.itemType == Item.ItemType.Consumable)  // HOW CAN I FIND TO THE RIGHT ITEM  POSITION??
					{
						
						UseConsumable(slots[i],i,true);
					}
			
					
					

					
				}
		
				if(tooltip == "")
				{
					showTooltip = false;
				}
			
				i++;


			}

		
		}


	}

I HOPE everbody can help… but if i call my function :

	bool InventoryContains (int id)
	{
		bool result = false;
		for (int i = 0; i < inventory.Count; i++)
		{
			result =  inventory[i].itemID == id;
			if(result)
			{
				break;
			}
		}
		return result;

	}

	private void UseConsumable(Item item, int slot, bool deleteItem)
	{
		switch (item.itemID) {
		case 2:
	
		print ("used consumable : " + item.itemName);
			
		break;


		}
		if (deleteItem) {
			inventory [slot] = new Item ();
		}
		}

Every Items with type consumable will be delete…

thanks for all

I can only see where all items of that specific type will be deleted. If item.itemID 5 has a quantity of 8 and you use 1, then that script will remove all 8, instead of 1.

You simply have no math for reduction of stacks of items.

Line 53 and line 56 MAY be the culprit. you’re in a for loop at the section of the code. I’m pretty sure the mouse event you’re checking will be the same through the lifetime of that for loop and thus hit that clause for every i and consume each item in the inventory slot by slot everytime you click.

Might be wrong though, only glanced at your code quickly since I’m headed to bed.