void Update() { if (inRange == true && Input.GetKey(KeyCode.E)) { if (!inv.invFull) { inv.AddItem(itemID); Destroy(gameObject); } else if (!hbar.hotbarfull) { hbar.AddItemHotbar(itemID); Destroy(gameObject); } if (hbar.hotbarfull && inv.invFull) { print("full"); } } }
void DrawInventory() { Event e = Event.current; int i = 0; for (int y = 0; y < slotsY; y++) //slots on y { for (int x = 0; x < slotsX; x++) //slots on x { Rect slotRect = new Rect(Screen.width / 3 + x * 60, Screen.height / 4 + y * 60, 50, 50); // slot location and size GUI.Box(new Rect(slotRect), "", skin.GetStyle("Slot")); // draw box slots[i] = inventory[i]; // list of slots is now equal to the amount of newly drawn invslots if (slots[i].itemName != null) // if the slot does have an item in it, based off of name, empty item doesnt have a name { GUI.DrawTexture(slotRect, slots[i].itemIcon); //draw the icon of the item that is in the slots if (slotRect.Contains(Event.current.mousePosition)) // if your cursor is is the box { tooltip = CreatTooltip(slots[i]); //show tooltip showTooltip = true; if (e.button == 0 && e.type == EventType.MouseDrag && !draggingItem) //drag item and empty slot { 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; } if (e.isMouse && e.type == EventType.MouseDown && e.button == 1) { if (slots[i].itemType == Item.ItemType.Consumable) { clayton.HPBar.SetHP(clayton.HPBar.getCurrentHPValue + slots[i].itemHealAmount); clayton.sBar.SetStam(clayton.sBar.getCurrentStamValue + slots[i].itemStamCost); clayton.MPBar.SetMP(clayton.MPBar.getCurrentMPValue + slots[i].itemManaCost); inventory[i] = new Item(); } }// middle mouse auto equipts to hotbar if (e.isMouse && e.type == EventType.MouseDown && e.button == 2 && hbar.hotbarfull == false) { hbar.AddItemHotbar(inventory[i].itemID); inventory[i] = new Item(); } } } else {//drop into slot if (slotRect.Contains(Event.current.mousePosition)) { if (e.type == EventType.MouseUp && draggingItem) { inventory[i] = draggedItem; draggingItem = false; draggedItem = null; } } } if (tooltip == "") { showTooltip = false; } i++; } } }