Greetings World, I have a little problem and I mean not my bad english 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