public void deleteItems(Item_On_Object item)
 {
     for (int i = 0; i < blueprintDatabase.blueprints.Count; i++)
     {
         if (blueprintDatabase.blueprints[i].finalItem.Equals(item))
         {
             for (int k = 0; k < blueprintDatabase.blueprints[i].ingredients.Count; k++)
             {
                 for (int z = 0; z < itemInCraftSystem.Count; z++)
                 {
                     if (itemInCraftSystem[z].itemID == blueprintDatabase.blueprints[i].ingredients[k])
                     {
                         if (itemInCraftSystem[z].itemValue == blueprintDatabase.blueprints[i].amount[k])
                         {
                             itemInCraftSystem.RemoveAt(z);
                             Destroy(itemInCraftSystemGameObject[z]);
                             itemInCraftSystemGameObject.RemoveAt(z);
                             ListWithItem();
                             break;
                         }
                         else if (itemInCraftSystem[z].itemValue >= blueprintDatabase.blueprints[i].amount[k])
                         {
                             itemInCraftSystem[z].itemValue = itemInCraftSystem[z].itemValue - blueprintDatabase.blueprints[i].amount[k];
                             ListWithItem();
                             break;
                         }
                     }
                 }
             }
         }
     }
 }
 void UnEquipWeapon(Item_On_Object item)
 {
     if (item.itemType == ItemType.Weapon)
     {
         //delete the weapon if you unequip the weapon
     }
 }
 public void EquiptItem(Item_On_Object item)
 {
     if (ItemEquip != null)
     {
         ItemEquip(item);
     }
 }
Exemple #4
0
    public void addItemToStorage(int id, int value)
    {
        Item_On_Object item = itemDatabase.getItemByID(id);

        item.itemValue = value;
        storageItems.Add(item);
    }
 void UnEquipBackpack(Item_On_Object item)
 {
     if (item.itemType == ItemType.Backpack)
     {
         changeInventorySize(normalSize);
     }
 }
 public void ConsumeItem(Item_On_Object item)
 {
     if (ItemConsumed != null)
     {
         ItemConsumed(item);
     }
 }
 public void UnEquipItem1(Item_On_Object item)
 {
     if (UnEquipItem != null)
     {
         UnEquipItem(item);
     }
 }
    public void OnPointerEnter(PointerEventData data)                               //if you hit a item in the slot
    {
        if (tooltip != null)
        {
            item         = GetComponent <ItemOnObject>().item;          //we get the item
            tooltip.item = item;                                        //set the item in the tooltip
            tooltip.activateTooltip();                                  //set all informations of the item in the tooltip
            if (canvasRectTransform == null)
            {
                return;
            }


            Vector3[] slotCorners = new Vector3[4];                      //get the corners of the slot
            GetComponent <RectTransform>().GetWorldCorners(slotCorners); //get the corners of the slot

            Vector2 localPointerPosition;
            if (RectTransformUtility.ScreenPointToLocalPointInRectangle(canvasRectTransform, slotCorners[3], data.pressEventCamera, out localPointerPosition))   // and set the localposition of the tooltip...
            {
                if (transform.parent.parent.parent.GetComponent <Hotbar>() == null)
                {
                    tooltipRectTransform.localPosition = localPointerPosition;          //at the right bottom side of the slot
                }
                else
                {
                    tooltipRectTransform.localPosition = new Vector3(localPointerPosition.x, localPointerPosition.y + tooltip.tooltipHeight);
                }
            }
        }
    }
 void EquipWeapon(Item_On_Object item)
 {
     if (item.itemType == ItemType.Weapon)
     {
         //add the weapon if you unequip the weapon
     }
 }
 public void OnUnEquipItem(Item_On_Object item)
 {
     for (int i = 0; i < item.itemAttributes.Count; i++)
     {
         if (item.itemAttributes[i].attributeName == "Health")
         {
             maxHealth -= item.itemAttributes[i].attributeValue;
         }
         if (item.itemAttributes[i].attributeName == "Mana")
         {
             maxMana -= item.itemAttributes[i].attributeValue;
         }
         if (item.itemAttributes[i].attributeName == "Armor")
         {
             maxArmor -= item.itemAttributes[i].attributeValue;
         }
         if (item.itemAttributes[i].attributeName == "Damage")
         {
             maxDamage -= item.itemAttributes[i].attributeValue;
         }
     }
     //if (HPMANACanvas != null)
     //{
     //    UpdateManaBar();
     //    UpdateHPBar();
     //}
 }
Exemple #11
0
    public void createDuplication(GameObject Item)
    {
        Item_On_Object item        = Item.GetComponent <ItemOnObject>().item;
        GameObject     duplication = GameObject.FindGameObjectWithTag("MainInventory").GetComponent <Inventory>().addItemToInventory(item.itemID, item.itemValue);
        //  duplication.transform.parent.parent.parent.GetComponent<Inventory>().stackableSettings();
//      Item.GetComponent<ConsumeItem>().duplication = duplication;
//      duplication.GetComponent<ConsumeItem>().duplication = Item;
    }
    public void createDuplication(GameObject Item)
    {
        Item_On_Object item = Item.GetComponent <ItemOnObject>().item;
        GameObject     dup  = mainInventory.GetComponent <Inventory>().addItemToInventory(item.itemID, item.itemValue);

        Item.GetComponent <ConsumeItem>().duplication = dup;
        dup.GetComponent <ConsumeItem>().duplication  = Item;
    }
    //void setUFPSSettings()
    //{
    //    itemPrefab = Resources.Load("Prefabs/Item") as GameObject;
    //    hotbarPrefab = Resources.Load("Prefabs/Panel - Hotbar") as GameObject;

    //    if(!inputManagerDatabase.UFPS)
    //    {
    //        if (itemPrefab.GetComponent<UFPS_ConsumeItem>() != null)
    //            DestroyImmediate(itemPrefab.GetComponent<UFPS_ConsumeItem>(), true);
    //        if (hotbarPrefab.GetComponent<UFPS_Hotbar>())
    //            DestroyImmediate(hotbarPrefab.GetComponent<UFPS_Hotbar>(), true);
    //    }
    //    else
    //    {
    //        itemPrefab.AddComponent<UFPS_ConsumeItem>();
    //        hotbarPrefab.AddComponent<UFPS_Hotbar>();
    //    }

    //}

    void addItem()                                          //add new item to the itemdatabase
    {
        EditorUtility.SetDirty(inventoryItemList);          //message scriptable object for incoming changes
        Item_On_Object newItem = new Item_On_Object();      //create a empty mask of an item

        newItem.itemName = "New Item";                      //set the name as "new Item"
        inventoryItemList.itemList.Add(newItem);            //and add this to the itemdatabase
        EditorUtility.SetDirty(inventoryItemList);          //message scriptable object that you added something
    }
 public void deleteItemFromInventory(Item_On_Object item)
 {
     for (int i = 0; i < ItemsInInventory.Count; i++)
     {
         if (item.Equals(ItemsInInventory[i]))
         {
             ItemsInInventory.RemoveAt(i);
         }
     }
 }
    //void UpdateHPBar()
    //{
    //    hpText.text = (currentHealth + "/" + maxHealth);
    //    float fillAmount = currentHealth / maxHealth;
    //    hpImage.fillAmount = fillAmount;
    //}

    //void UpdateManaBar()
    //{
    //    manaText.text = (currentMana + "/" + maxMana);
    //    float fillAmount = currentMana / maxMana;
    //    manaImage.fillAmount = fillAmount;
    //}


    public void OnConsumeItem(Item_On_Object item)
    {
        for (int i = 0; i < item.itemAttributes.Count; i++)
        {
            if (item.itemAttributes[i].attributeName == "Health")
            {
                if ((currentHealth + item.itemAttributes[i].attributeValue) > maxHealth)
                {
                    currentHealth = maxHealth;
                }
                else
                {
                    currentHealth += item.itemAttributes[i].attributeValue;
                }
            }
            if (item.itemAttributes[i].attributeName == "Mana")
            {
                if ((currentMana + item.itemAttributes[i].attributeValue) > maxMana)
                {
                    currentMana = maxMana;
                }
                else
                {
                    currentMana += item.itemAttributes[i].attributeValue;
                }
            }
            if (item.itemAttributes[i].attributeName == "Armor")
            {
                if ((currentArmor + item.itemAttributes[i].attributeValue) > maxArmor)
                {
                    currentArmor = maxArmor;
                }
                else
                {
                    currentArmor += item.itemAttributes[i].attributeValue;
                }
            }
            if (item.itemAttributes[i].attributeName == "Damage")
            {
                if ((currentDamage + item.itemAttributes[i].attributeValue) > maxDamage)
                {
                    currentDamage = maxDamage;
                }
                else
                {
                    currentDamage += item.itemAttributes[i].attributeValue;
                }
            }
        }
        //if (HPMANACanvas != null)
        //{
        //    UpdateManaBar();
        //    UpdateHPBar();
        //}
    }
 public int getPositionOfItem(Item_On_Object item)
 {
     for (int i = 0; i < SlotContainer.transform.childCount; i++)
     {
         if (SlotContainer.transform.GetChild(i).childCount != 0)
         {
             Item_On_Object item2 = SlotContainer.transform.GetChild(i).GetChild(0).GetComponent <ItemOnObject>().item;
             if (item.Equals(item2))
             {
                 return(i);
             }
         }
     }
     return(-1);
 }
 public GameObject getItemGameObject(Item_On_Object item)
 {
     for (int k = 0; k < SlotContainer.transform.childCount; k++)
     {
         if (SlotContainer.transform.GetChild(k).childCount != 0)
         {
             GameObject     itemGameObject = SlotContainer.transform.GetChild(k).GetChild(0).gameObject;
             Item_On_Object itemObject     = itemGameObject.GetComponent <ItemOnObject>().item;
             if (itemObject.Equals(item))
             {
                 return(itemGameObject);
             }
         }
     }
     return(null);
 }
    void Start()
    {
        item = GetComponent <ItemOnObject>().item;
        if (GameObject.FindGameObjectWithTag("Tooltip") != null)
        {
            tooltip = GameObject.FindGameObjectWithTag("Tooltip").GetComponent <Tooltip>();
        }
        if (GameObject.FindGameObjectWithTag("EquipmentSystem") != null)
        {
            eS = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().characterSystem.GetComponent <EquipmentSystem>();
        }

        if (GameObject.FindGameObjectWithTag("MainInventory") != null)
        {
            mainInventory = GameObject.FindGameObjectWithTag("MainInventory");
        }
    }
 void OnBackpack(Item_On_Object item)
 {
     if (item.itemType == ItemType.Backpack)
     {
         for (int i = 0; i < item.itemAttributes.Count; i++)
         {
             if (mainInventory == null)
             {
                 mainInventory = inventory.GetComponent <Inventory>();
             }
             mainInventory.sortItems();
             if (item.itemAttributes[i].attributeName == "Slots")
             {
                 changeInventorySize(item.itemAttributes[i].attributeValue);
             }
         }
     }
 }
Exemple #20
0
    void Start()
    {
        if (inputManagerDatabase == null)
        {
            inputManagerDatabase = (InputManager)Resources.Load("InputManager");
        }

        player = GameObject.FindGameObjectWithTag("Player");
        inv    = inventory.GetComponent <Inventory>();
        ItemDataBaseList inventoryItemList = (ItemDataBaseList)Resources.Load("ItemDatabase");

        int creatingItemsForChest = 1;

        int randomItemAmount = Random.Range(1, itemAmount);

        while (creatingItemsForChest < randomItemAmount)
        {
            int randomItemNumber = Random.Range(1, inventoryItemList.itemList.Count - 1);
            int raffle           = Random.Range(1, 100);

            if (raffle <= inventoryItemList.itemList[randomItemNumber].rarity)
            {
                int            randomValue = Random.Range(1, inventoryItemList.itemList[randomItemNumber].getCopy().maxStack);
                Item_On_Object item        = inventoryItemList.itemList[randomItemNumber].getCopy();
                item.itemValue = randomValue;
                storageItems.Add(item);
                creatingItemsForChest++;
            }
        }

        if (GameObject.FindGameObjectWithTag("Timer") != null)
        {
            timerImage = GameObject.FindGameObjectWithTag("Timer").GetComponent <Image>();
            timer      = GameObject.FindGameObjectWithTag("Timer");
            timer.SetActive(false);
        }
        if (GameObject.FindGameObjectWithTag("Tooltip") != null)
        {
            tooltip = GameObject.FindGameObjectWithTag("Tooltip").GetComponent <Tooltip>();
        }
    }
    public void deleteItemFromInventoryWithGameObject(Item_On_Object item)
    {
        for (int i = 0; i < ItemsInInventory.Count; i++)
        {
            if (item.Equals(ItemsInInventory[i]))
            {
                ItemsInInventory.RemoveAt(i);
            }
        }

        for (int k = 0; k < SlotContainer.transform.childCount; k++)
        {
            if (SlotContainer.transform.GetChild(k).childCount != 0)
            {
                GameObject     itemGameObject = SlotContainer.transform.GetChild(k).GetChild(0).gameObject;
                Item_On_Object itemObject     = itemGameObject.GetComponent <ItemOnObject>().item;
                if (itemObject.Equals(item))
                {
                    Destroy(itemGameObject);
                    break;
                }
            }
        }
    }
Exemple #22
0
 public Blueprint(List <int> ingredients, int amountOfFinalItem, List <int> amount, Item_On_Object item)
 {
     this.ingredients = ingredients;
     this.amount      = amount;
     finalItem        = item;
 }
    public void OnPointerDown(PointerEventData data)
    {
        if (this.gameObject.transform.parent.parent.parent.GetComponent <EquipmentSystem>() == null)
        {
            bool      gearable  = false;
            Inventory inventory = transform.parent.parent.parent.GetComponent <Inventory>();

            if (eS != null)
            {
                itemTypeOfSlot = eS.itemTypeOfSlots;
            }

            if (data.button == PointerEventData.InputButton.Right)
            {
                //item from craft system to inventory
                if (transform.parent.GetComponent <CraftResultSlot>() != null)
                {
                    bool check = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().inventory.GetComponent <Inventory>().checkIfItemAllreadyExist(item.itemID, item.itemValue);

                    if (!check)
                    {
                        GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().inventory.GetComponent <Inventory>().addItemToInventory(item.itemID, item.itemValue);
                        GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().inventory.GetComponent <Inventory>().stackableSettings();
                    }
                    CraftSystem cS = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().craftSystem.GetComponent <CraftSystem>();
                    cS.deleteItems(item);
                    CraftResultSlot result = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().craftSystem.transform.GetChild(3).GetComponent <CraftResultSlot>();
                    result.temp = 0;
                    tooltip.deactivateTooltip();
                    gearable = true;
                    GameObject.FindGameObjectWithTag("MainInventory").GetComponent <Inventory>().updateItemList();
                }
                else
                {
                    bool stop = false;
                    if (eS != null)
                    {
                        for (int i = 0; i < eS.slotsInTotal; i++)
                        {
                            if (itemTypeOfSlot[i].Equals(item.itemType))
                            {
                                if (eS.transform.GetChild(1).GetChild(i).childCount == 0)
                                {
                                    stop = true;
                                    if (eS.transform.GetChild(1).GetChild(i).parent.parent.GetComponent <EquipmentSystem>() != null && this.gameObject.transform.parent.parent.parent.GetComponent <EquipmentSystem>() != null)
                                    {
                                    }
                                    else
                                    {
                                        inventory.EquiptItem(item);
                                    }

                                    this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
                                    this.gameObject.GetComponent <RectTransform>().localPosition = Vector3.zero;
                                    eS.gameObject.GetComponent <Inventory>().updateItemList();
                                    inventory.updateItemList();
                                    gearable = true;
                                    if (duplication != null)
                                    {
                                        Destroy(duplication.gameObject);
                                    }
                                    break;
                                }
                            }
                        }


                        if (!stop)
                        {
                            for (int i = 0; i < eS.slotsInTotal; i++)
                            {
                                if (itemTypeOfSlot[i].Equals(item.itemType))
                                {
                                    if (eS.transform.GetChild(1).GetChild(i).childCount != 0)
                                    {
                                        GameObject     otherItemFromCharacterSystem = eS.transform.GetChild(1).GetChild(i).GetChild(0).gameObject;
                                        Item_On_Object otherSlotItem = otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item;
                                        if (item.itemType == ItemType.UFPS_Weapon)
                                        {
                                            inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item);
                                            inventory.EquiptItem(item);
                                        }
                                        else
                                        {
                                            inventory.EquiptItem(item);
                                            if (item.itemType != ItemType.Backpack)
                                            {
                                                inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item);
                                            }
                                        }
                                        if (this == null)
                                        {
                                            GameObject dropItem = (GameObject)Instantiate(otherSlotItem.itemModel);
                                            dropItem.AddComponent <PickUpItem>();
                                            dropItem.GetComponent <PickUpItem>().item = otherSlotItem;
                                            dropItem.transform.localPosition          = GameObject.FindGameObjectWithTag("Player").transform.localPosition;
                                            inventory.OnUpdateItemList();
                                        }
                                        else
                                        {
                                            otherItemFromCharacterSystem.transform.SetParent(this.transform.parent);
                                            otherItemFromCharacterSystem.GetComponent <RectTransform>().localPosition = Vector3.zero;
                                            if (this.gameObject.transform.parent.parent.parent.GetComponent <Hotbar>() != null)
                                            {
                                                createDuplication(otherItemFromCharacterSystem);
                                            }

                                            this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
                                            this.gameObject.GetComponent <RectTransform>().localPosition = Vector3.zero;
                                        }

                                        gearable = true;
                                        if (duplication != null)
                                        {
                                            Destroy(duplication.gameObject);
                                        }
                                        eS.gameObject.GetComponent <Inventory>().updateItemList();
                                        inventory.OnUpdateItemList();
                                        break;
                                    }
                                }
                            }
                        }
                    }
                }
                if (!gearable && item.itemType != ItemType.UFPS_Ammo && item.itemType != ItemType.UFPS_Grenade)
                {
                    Item_On_Object itemFromDup = null;
                    if (duplication != null)
                    {
                        itemFromDup = duplication.GetComponent <ItemOnObject>().item;
                    }

                    inventory.ConsumeItem(item);

                    item.itemValue--;
                    if (itemFromDup != null)
                    {
                        duplication.GetComponent <ItemOnObject>().item.itemValue--;
                        if (itemFromDup.itemValue <= 0)
                        {
                            if (tooltip != null)
                            {
                                tooltip.deactivateTooltip();
                            }
                            inventory.deleteItemFromInventory(item);
                            Destroy(duplication.gameObject);
                        }
                    }
                    if (item.itemValue <= 0)
                    {
                        if (tooltip != null)
                        {
                            tooltip.deactivateTooltip();
                        }
                        inventory.deleteItemFromInventory(item);
                        Destroy(this.gameObject);
                    }
                }
            }
        }
    }
    public void consumeIt()
    {
        Inventory inventory = transform.parent.parent.parent.GetComponent <Inventory>();

        bool gearable = false;

        if (GameObject.FindGameObjectWithTag("EquipmentSystem") != null)
        {
            eS = GameObject.FindGameObjectWithTag("Player").GetComponent <PlayerInventory>().characterSystem.GetComponent <EquipmentSystem>();
        }

        if (eS != null)
        {
            itemTypeOfSlot = eS.itemTypeOfSlots;
        }

        Item_On_Object itemFromDup = null;

        if (duplication != null)
        {
            itemFromDup = duplication.GetComponent <ItemOnObject>().item;
        }

        bool stop = false;

        if (eS != null)
        {
            for (int i = 0; i < eS.slotsInTotal; i++)
            {
                if (itemTypeOfSlot[i].Equals(item.itemType))
                {
                    if (eS.transform.GetChild(1).GetChild(i).childCount == 0)
                    {
                        stop = true;
                        this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
                        this.gameObject.GetComponent <RectTransform>().localPosition = Vector3.zero;
                        eS.gameObject.GetComponent <Inventory>().updateItemList();
                        inventory.updateItemList();
                        inventory.EquiptItem(item);
                        gearable = true;
                        if (duplication != null)
                        {
                            Destroy(duplication.gameObject);
                        }
                        break;
                    }
                }
            }

            if (!stop)
            {
                for (int i = 0; i < eS.slotsInTotal; i++)
                {
                    if (itemTypeOfSlot[i].Equals(item.itemType))
                    {
                        if (eS.transform.GetChild(1).GetChild(i).childCount != 0)
                        {
                            GameObject     otherItemFromCharacterSystem = eS.transform.GetChild(1).GetChild(i).GetChild(0).gameObject;
                            Item_On_Object otherSlotItem = otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item;
                            if (item.itemType == ItemType.UFPS_Weapon)
                            {
                                inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item);
                                inventory.EquiptItem(item);
                            }
                            else
                            {
                                inventory.EquiptItem(item);
                                if (item.itemType != ItemType.Backpack)
                                {
                                    inventory.UnEquipItem1(otherItemFromCharacterSystem.GetComponent <ItemOnObject>().item);
                                }
                            }
                            if (this == null)
                            {
                                GameObject dropItem = (GameObject)Instantiate(otherSlotItem.itemModel);
                                dropItem.AddComponent <PickUpItem>();
                                dropItem.GetComponent <PickUpItem>().item = otherSlotItem;
                                dropItem.transform.localPosition          = GameObject.FindGameObjectWithTag("Player").transform.localPosition;
                                inventory.OnUpdateItemList();
                            }
                            else
                            {
                                otherItemFromCharacterSystem.transform.SetParent(this.transform.parent);
                                otherItemFromCharacterSystem.GetComponent <RectTransform>().localPosition = Vector3.zero;
                                if (this.gameObject.transform.parent.parent.parent.GetComponent <Hotbar>() != null)
                                {
                                    createDuplication(otherItemFromCharacterSystem);
                                }

                                this.gameObject.transform.SetParent(eS.transform.GetChild(1).GetChild(i));
                                this.gameObject.GetComponent <RectTransform>().localPosition = Vector3.zero;
                            }

                            gearable = true;
                            if (duplication != null)
                            {
                                Destroy(duplication.gameObject);
                            }
                            eS.gameObject.GetComponent <Inventory>().updateItemList();
                            inventory.OnUpdateItemList();
                            break;
                        }
                    }
                }
            }
        }
        if (!gearable && item.itemType != ItemType.UFPS_Ammo && item.itemType != ItemType.UFPS_Grenade)
        {
            if (duplication != null)
            {
                itemFromDup = duplication.GetComponent <ItemOnObject>().item;
            }

            inventory.ConsumeItem(item);


            item.itemValue--;
            if (itemFromDup != null)
            {
                duplication.GetComponent <ItemOnObject>().item.itemValue--;
                if (itemFromDup.itemValue <= 0)
                {
                    if (tooltip != null)
                    {
                        tooltip.deactivateTooltip();
                    }
                    inventory.deleteItemFromInventory(item);
                    Destroy(duplication.gameObject);
                }
            }
            if (item.itemValue <= 0)
            {
                if (tooltip != null)
                {
                    tooltip.deactivateTooltip();
                }
                inventory.deleteItemFromInventory(item);
                Destroy(this.gameObject);
            }
        }
    }
    public void OnEndDrag(PointerEventData data)
    {
        GameObject.Find("Click").GetComponent <AudioSource>().Play();

        if (data.button == PointerEventData.InputButton.Left)
        {
            canvasGroup.blocksRaycasts = true;
            Transform newSlot = null;
            if (data.pointerEnter != null)
            {
                newSlot = data.pointerEnter.transform;
            }

            if (newSlot != null)
            {
                //getting the items from the slots, GameObjects and RectTransform
                GameObject     firstItemGameObject     = this.gameObject;
                GameObject     secondItemGameObject    = newSlot.parent.gameObject;
                RectTransform  firstItemRectTransform  = this.gameObject.GetComponent <RectTransform>();
                RectTransform  secondItemRectTransform = newSlot.parent.GetComponent <RectTransform>();
                Item_On_Object firstItem  = rectTransform.GetComponent <ItemOnObject>().item;
                Item_On_Object secondItem = new Item_On_Object();
                if (newSlot.parent.GetComponent <ItemOnObject>() != null)
                {
                    secondItem = newSlot.parent.GetComponent <ItemOnObject>().item;
                }

                //get some informations about the two items
                bool sameItem            = firstItem.itemName == secondItem.itemName;
                bool sameItemRerferenced = firstItem.Equals(secondItem);
                bool secondItemStack     = false;
                bool firstItemStack      = false;
                if (sameItem)
                {
                    firstItemStack  = firstItem.itemValue < firstItem.maxStack;
                    secondItemStack = secondItem.itemValue < secondItem.maxStack;
                }

                GameObject Inventory = secondItemRectTransform.parent.gameObject;
                if (Inventory.tag == "Slot")
                {
                    Inventory = secondItemRectTransform.parent.parent.parent.gameObject;
                }

                if (Inventory.tag.Equals("Slot"))
                {
                    Inventory = Inventory.transform.parent.parent.gameObject;
                }

                //dragging in an Inventory
                if (Inventory.GetComponent <Hotbar>() == null && Inventory.GetComponent <EquipmentSystem>() == null && Inventory.GetComponent <CraftSystem>() == null)
                {
                    //you cannot attach items to the resultslot of the craftsystem
                    if (newSlot.transform.parent.tag == "ResultSlot" || newSlot.transform.tag == "ResultSlot" || newSlot.transform.parent.parent.tag == "ResultSlot")
                    {
                        firstItemGameObject.transform.SetParent(oldSlot.transform);
                        firstItemRectTransform.localPosition = Vector3.zero;
                    }
                    else
                    {
                        int  newSlotChildCount = newSlot.transform.parent.childCount;
                        bool isOnSlot          = newSlot.transform.parent.GetChild(0).tag == "ItemIcon";
                        //dragging on a slot where allready is an item on
                        if (newSlotChildCount != 0 && isOnSlot)
                        {
                            //check if the items fits into the other item
                            bool fitsIntoStack = false;
                            if (sameItem)
                            {
                                fitsIntoStack = (firstItem.itemValue + secondItem.itemValue) <= firstItem.maxStack;
                            }
                            //if the item is stackable checking if the firstitemstack and seconditemstack is not full and check if they are the same items

                            if (inventory.stackable && sameItem && firstItemStack && secondItemStack)
                            {
                                GameObject.Find("Tasty_Voice").GetComponent <AudioSource>().Play();


                                //if the item does not fit into the other item
                                if (fitsIntoStack && !sameItemRerferenced)
                                {
                                    secondItem.itemValue = firstItem.itemValue + secondItem.itemValue;
                                    secondItemGameObject.transform.SetParent(newSlot.parent.parent);
                                    Destroy(firstItemGameObject);
                                    secondItemRectTransform.localPosition = Vector3.zero;
                                    if (secondItemGameObject.GetComponent <ConsumeItem>().duplication != null)
                                    {
                                        GameObject dup = secondItemGameObject.GetComponent <ConsumeItem>().duplication;
                                        dup.GetComponent <ItemOnObject>().item.itemValue = secondItem.itemValue;
                                        dup.GetComponent <SplitItem>().inv.stackableSettings();
                                        dup.transform.parent.parent.parent.GetComponent <Inventory>().updateItemList();
                                    }
                                }

                                else
                                {
                                    //creates the rest of the item
                                    int rest = (firstItem.itemValue + secondItem.itemValue) % firstItem.maxStack;

                                    //fill up the other stack and adds the rest to the other stack
                                    if (!fitsIntoStack && rest > 0)
                                    {
                                        firstItem.itemValue  = firstItem.maxStack;
                                        secondItem.itemValue = rest;

                                        firstItemGameObject.transform.SetParent(secondItemGameObject.transform.parent);
                                        secondItemGameObject.transform.SetParent(oldSlot.transform);

                                        firstItemRectTransform.localPosition  = Vector3.zero;
                                        secondItemRectTransform.localPosition = Vector3.zero;
                                    }
                                }
                            }
                            //if does not fit
                            else
                            {
                                //creates the rest of the item
                                int rest = 0;
                                if (sameItem)
                                {
                                    rest = (firstItem.itemValue + secondItem.itemValue) % firstItem.maxStack;
                                }

                                //fill up the other stack and adds the rest to the other stack
                                if (!fitsIntoStack && rest > 0)
                                {
                                    secondItem.itemValue = firstItem.maxStack;
                                    firstItem.itemValue  = rest;

                                    firstItemGameObject.transform.SetParent(secondItemGameObject.transform.parent);
                                    secondItemGameObject.transform.SetParent(oldSlot.transform);

                                    firstItemRectTransform.localPosition  = Vector3.zero;
                                    secondItemRectTransform.localPosition = Vector3.zero;
                                }
                                //if they are different items or the stack is full, they get swapped
                                else if (!fitsIntoStack && rest == 0)
                                {
                                    //if you are dragging an item from equipmentsystem to the inventory and try to swap it with the same itemtype
                                    if (oldSlot.transform.parent.parent.GetComponent <EquipmentSystem>() != null && firstItem.itemType == secondItem.itemType)
                                    {
                                        newSlot.transform.parent.parent.parent.parent.GetComponent <Inventory>().UnEquipItem1(firstItem);
                                        oldSlot.transform.parent.parent.GetComponent <Inventory>().EquiptItem(secondItem);

                                        firstItemGameObject.transform.SetParent(secondItemGameObject.transform.parent);
                                        secondItemGameObject.transform.SetParent(oldSlot.transform);
                                        secondItemRectTransform.localPosition = Vector3.zero;
                                        firstItemRectTransform.localPosition  = Vector3.zero;

                                        if (secondItemGameObject.GetComponent <ConsumeItem>().duplication != null)
                                        {
                                            Destroy(secondItemGameObject.GetComponent <ConsumeItem>().duplication);
                                        }
                                    }
                                    //if you are dragging an item from the equipmentsystem to the inventory and they are not from the same itemtype they do not get swapped.
                                    else if (oldSlot.transform.parent.parent.GetComponent <EquipmentSystem>() != null && firstItem.itemType != secondItem.itemType)
                                    {
                                        firstItemGameObject.transform.SetParent(oldSlot.transform);
                                        firstItemRectTransform.localPosition = Vector3.zero;
                                    }
                                    //swapping for the rest of the inventorys
                                    else if (oldSlot.transform.parent.parent.GetComponent <EquipmentSystem>() == null)
                                    {
                                        firstItemGameObject.transform.SetParent(secondItemGameObject.transform.parent);
                                        secondItemGameObject.transform.SetParent(oldSlot.transform);
                                        secondItemRectTransform.localPosition = Vector3.zero;
                                        firstItemRectTransform.localPosition  = Vector3.zero;
                                    }
                                }
                            }
                        }

                        //empty slot
                        else
                        {
                            if (newSlot.tag != "Slot" && newSlot.tag != "ItemIcon")
                            {
                                firstItemGameObject.transform.SetParent(oldSlot.transform);
                                firstItemRectTransform.localPosition = Vector3.zero;
                            }
                            else
                            {
                                firstItemGameObject.transform.SetParent(newSlot.transform);
                                firstItemRectTransform.localPosition = Vector3.zero;

                                if (newSlot.transform.parent.parent.GetComponent <EquipmentSystem>() == null && oldSlot.transform.parent.parent.GetComponent <EquipmentSystem>() != null)
                                {
                                    oldSlot.transform.parent.parent.GetComponent <Inventory>().UnEquipItem1(firstItem);
                                }
                            }
                        }
                    }
                }



                //dragging into a Hotbar
                if (Inventory.GetComponent <Hotbar>() != null)
                {
                    int  newSlotChildCount = newSlot.transform.parent.childCount;
                    bool isOnSlot          = newSlot.transform.parent.GetChild(0).tag == "ItemIcon";
                    //dragging on a slot where allready is an item on
                    if (newSlotChildCount != 0 && isOnSlot)
                    {
                        //check if the items fits into the other item
                        bool fitsIntoStack = false;
                        if (sameItem)
                        {
                            fitsIntoStack = (firstItem.itemValue + secondItem.itemValue) <= firstItem.maxStack;
                        }
                        //if the item is stackable checking if the firstitemstack and seconditemstack is not full and check if they are the same items

                        if (inventory.stackable && sameItem && firstItemStack && secondItemStack)
                        {
                            //if the item does not fit into the other item
                            if (fitsIntoStack && !sameItemRerferenced)
                            {
                                secondItem.itemValue = firstItem.itemValue + secondItem.itemValue;
                                secondItemGameObject.transform.SetParent(newSlot.parent.parent);
                                Destroy(firstItemGameObject);
                                secondItemRectTransform.localPosition = Vector3.zero;
                                if (secondItemGameObject.GetComponent <ConsumeItem>().duplication != null)
                                {
                                    GameObject dup = secondItemGameObject.GetComponent <ConsumeItem>().duplication;
                                    dup.GetComponent <ItemOnObject>().item.itemValue = secondItem.itemValue;
                                    Inventory.GetComponent <Inventory>().stackableSettings();
                                    dup.transform.parent.parent.parent.GetComponent <Inventory>().updateItemList();
                                }
                            }

                            else
                            {
                                //creates the rest of the item
                                int rest = (firstItem.itemValue + secondItem.itemValue) % firstItem.maxStack;

                                //fill up the other stack and adds the rest to the other stack
                                if (!fitsIntoStack && rest > 0)
                                {
                                    firstItem.itemValue  = firstItem.maxStack;
                                    secondItem.itemValue = rest;

                                    firstItemGameObject.transform.SetParent(secondItemGameObject.transform.parent);
                                    secondItemGameObject.transform.SetParent(oldSlot.transform);

                                    firstItemRectTransform.localPosition  = Vector3.zero;
                                    secondItemRectTransform.localPosition = Vector3.zero;

                                    createDuplication(this.gameObject);
                                    secondItemGameObject.GetComponent <ConsumeItem>().duplication.GetComponent <ItemOnObject>().item = secondItem;
                                    secondItemGameObject.GetComponent <SplitItem>().inv.stackableSettings();
                                }
                            }
                        }
                        //if does not fit
                        else
                        {
                            //creates the rest of the item
                            int rest = 0;
                            if (sameItem)
                            {
                                rest = (firstItem.itemValue + secondItem.itemValue) % firstItem.maxStack;
                            }

                            bool fromEquip = oldSlot.transform.parent.parent.GetComponent <EquipmentSystem>() != null;

                            //fill up the other stack and adds the rest to the other stack
                            if (!fitsIntoStack && rest > 0)
                            {
                                secondItem.itemValue = firstItem.maxStack;
                                firstItem.itemValue  = rest;

                                createDuplication(this.gameObject);

                                firstItemGameObject.transform.SetParent(secondItemGameObject.transform.parent);
                                secondItemGameObject.transform.SetParent(oldSlot.transform);

                                firstItemRectTransform.localPosition  = Vector3.zero;
                                secondItemRectTransform.localPosition = Vector3.zero;
                            }
                            //if they are different items or the stack is full, they get swapped
                            else if (!fitsIntoStack && rest == 0)
                            {
                                if (!fromEquip)
                                {
                                    firstItemGameObject.transform.SetParent(secondItemGameObject.transform.parent);
                                    secondItemGameObject.transform.SetParent(oldSlot.transform);
                                    secondItemRectTransform.localPosition = Vector3.zero;
                                    firstItemRectTransform.localPosition  = Vector3.zero;

                                    if (oldSlot.transform.parent.parent.gameObject.Equals(GameObject.FindGameObjectWithTag("MainInventory")))
                                    {
                                        Destroy(secondItemGameObject.GetComponent <ConsumeItem>().duplication);
                                        createDuplication(firstItemGameObject);
                                    }
                                    else
                                    {
                                        createDuplication(firstItemGameObject);
                                    }
                                }
                                else
                                {
                                    firstItemGameObject.transform.SetParent(oldSlot.transform);
                                    firstItemRectTransform.localPosition = Vector3.zero;
                                }
                            }
                        }
                    }
                    //empty slot
                    else
                    {
                        if (newSlot.tag != "Slot" && newSlot.tag != "ItemIcon")
                        {
                            firstItemGameObject.transform.SetParent(oldSlot.transform);
                            firstItemRectTransform.localPosition = Vector3.zero;
                        }
                        else
                        {
                            firstItemGameObject.transform.SetParent(newSlot.transform);
                            firstItemRectTransform.localPosition = Vector3.zero;

                            if (newSlot.transform.parent.parent.GetComponent <EquipmentSystem>() == null && oldSlot.transform.parent.parent.GetComponent <EquipmentSystem>() != null)
                            {
                                oldSlot.transform.parent.parent.GetComponent <Inventory>().UnEquipItem1(firstItem);
                            }
                            createDuplication(firstItemGameObject);
                        }
                    }
                }


                //dragging into a equipmentsystem/charactersystem
                if (Inventory.GetComponent <EquipmentSystem>() != null)
                {
                    ItemType[] itemTypeOfSlots   = GameObject.FindGameObjectWithTag("EquipmentSystem").GetComponent <EquipmentSystem>().itemTypeOfSlots;
                    int        newSlotChildCount = newSlot.transform.parent.childCount;
                    bool       isOnSlot          = newSlot.transform.parent.GetChild(0).tag == "ItemIcon";
                    bool       sameItemType      = firstItem.itemType == secondItem.itemType;
                    bool       fromHot           = oldSlot.transform.parent.parent.GetComponent <Hotbar>() != null;

                    //dragging on a slot where allready is an item on
                    if (newSlotChildCount != 0 && isOnSlot)
                    {
                        //items getting swapped if they are the same itemtype
                        if (sameItemType && !sameItemRerferenced) //
                        {
                            Transform temp1 = secondItemGameObject.transform.parent.parent.parent;
                            Transform temp2 = oldSlot.transform.parent.parent;

                            firstItemGameObject.transform.SetParent(secondItemGameObject.transform.parent);
                            secondItemGameObject.transform.SetParent(oldSlot.transform);
                            secondItemRectTransform.localPosition = Vector3.zero;
                            firstItemRectTransform.localPosition  = Vector3.zero;

                            if (!temp1.Equals(temp2))
                            {
                                if (firstItem.itemType == ItemType.UFPS_Weapon)
                                {
                                    Inventory.GetComponent <Inventory>().UnEquipItem1(secondItem);
                                    Inventory.GetComponent <Inventory>().EquiptItem(firstItem);
                                }
                                else
                                {
                                    Inventory.GetComponent <Inventory>().EquiptItem(firstItem);
                                    if (secondItem.itemType != ItemType.Backpack)
                                    {
                                        Inventory.GetComponent <Inventory>().UnEquipItem1(secondItem);
                                    }
                                }
                            }

                            if (fromHot)
                            {
                                createDuplication(secondItemGameObject);
                            }
                        }
                        //if they are not from the same Itemtype the dragged one getting placed back
                        else
                        {
                            firstItemGameObject.transform.SetParent(oldSlot.transform);
                            firstItemRectTransform.localPosition = Vector3.zero;

                            if (fromHot)
                            {
                                createDuplication(firstItemGameObject);
                            }
                        }
                    }
                    //if the slot is empty
                    else
                    {
                        for (int i = 0; i < newSlot.parent.childCount; i++)
                        {
                            if (newSlot.Equals(newSlot.parent.GetChild(i)))
                            {
                                //checking if it is the right slot for the item
                                if (itemTypeOfSlots[i] == transform.GetComponent <ItemOnObject>().item.itemType)
                                {
                                    transform.SetParent(newSlot);
                                    rectTransform.localPosition = Vector3.zero;

                                    if (!oldSlot.transform.parent.parent.Equals(newSlot.transform.parent.parent))
                                    {
                                        Inventory.GetComponent <Inventory>().EquiptItem(firstItem);
                                    }
                                }
                                //else it get back to the old slot
                                else
                                {
                                    transform.SetParent(oldSlot.transform);
                                    rectTransform.localPosition = Vector3.zero;
                                    if (fromHot)
                                    {
                                        createDuplication(firstItemGameObject);
                                    }
                                }
                            }
                        }
                    }
                }

                //           if (Inventory.GetComponent<CraftSystem>() != null)
                //           {
                //               CraftSystem cS = Inventory.GetComponent<CraftSystem>();
                //               int newSlotChildCount = newSlot.transform.parent.childCount;


                //                bool isOnSlot = newSlot.transform.parent.GetChild(0).tag == "ItemIcon";
                //                //dragging on a slot where allready is an item on
                //                if (newSlotChildCount != 0 && isOnSlot)
                //                {
                //                    //check if the items fits into the other item
                //                    bool fitsIntoStack = false;
                //                    if (sameItem)
                //                        fitsIntoStack = (firstItem.itemValue + secondItem.itemValue) <= firstItem.maxStack;
                //if the item is stackable checking if the firstitemstack and seconditemstack is not full and check if they are the same items

                //                  if (inventory.stackable && sameItem && firstItemStack && secondItemStack)
                //                  {
                //if the item does not fit into the other item
                //                      if (fitsIntoStack && !sameItemRerferenced)
                //                      {
                //                          secondItem.itemValue = firstItem.itemValue + secondItem.itemValue;
                //                          secondItemGameObject.transform.SetParent(newSlot.parent.parent);
                //                          Destroy(firstItemGameObject);
                //                          secondItemRectTransform.localPosition = Vector3.zero;


                //                        if (secondItemGameObject.GetComponent<ConsumeItem>().duplication != null)
                //                          {
                //                              GameObject dup = secondItemGameObject.GetComponent<ConsumeItem>().duplication;
                //                                dup.GetComponent<ItemOnObject>().item.itemValue = secondItem.itemValue;
                //                                dup.GetComponent<SplitItem>().inv.stackableSettings();
                //                                dup.transform.parent.parent.parent.GetComponent<Inventory>().updateItemList();
                //                            }
                //                            cS.ListWithItem();
                //                        }

                //                      else
                //                      {
                //creates the rest of the item
                //                           int rest = (firstItem.itemValue + secondItem.itemValue) % firstItem.maxStack;

                //fill up the other stack and adds the rest to the other stack
                //                           if (!fitsIntoStack && rest > 0)
                //                           {
                //                               firstItem.itemValue = firstItem.maxStack;
                //                               secondItem.itemValue = rest;

                //                               firstItemGameObject.transform.SetParent(secondItemGameObject.transform.parent);
                //                               secondItemGameObject.transform.SetParent(oldSlot.transform);

                //                               firstItemRectTransform.localPosition = Vector3.zero;
                //                               secondItemRectTransform.localPosition = Vector3.zero;
                //                              cS.ListWithItem();


                //                          }
                //                      }

                //                }
                //if does not fit
                //              else
                //            {
                //creates the rest of the item
                //                  int rest = 0;
                //                  if (sameItem)
                //                      rest = (firstItem.itemValue + secondItem.itemValue) % firstItem.maxStack;

                //fill up the other stack and adds the rest to the other stack
                //                if (!fitsIntoStack && rest > 0)
                //                   {
                //                       secondItem.itemValue = firstItem.maxStack;
                //                       firstItem.itemValue = rest;
//
//                              firstItemGameObject.transform.SetParent(secondItemGameObject.transform.parent);
//                            secondItemGameObject.transform.SetParent(oldSlot.transform);

                //                          firstItemRectTransform.localPosition = Vector3.zero;
                //                        secondItemRectTransform.localPosition = Vector3.zero;
                //                      cS.ListWithItem();

                //                }
                //if they are different items or the stack is full, they get swapped
                //                   else if (!fitsIntoStack && rest == 0)
                //                 {
                //if you are dragging an item from equipmentsystem to the inventory and try to swap it with the same itemtype
                //                   if (oldSlot.transform.parent.parent.GetComponent<EquipmentSystem>() != null && firstItem.itemType == secondItem.itemType)
                //                 {

//                                    firstItemGameObject.transform.SetParent(secondItemGameObject.transform.parent);
//                                  secondItemGameObject.transform.SetParent(oldSlot.transform);
//                                secondItemRectTransform.localPosition = Vector3.zero;
//                              firstItemRectTransform.localPosition = Vector3.zero;

                //                               oldSlot.transform.parent.parent.GetComponent<Inventory>().EquiptItem(secondItem);
                //                                 newSlot.transform.parent.parent.parent.parent.GetComponent<Inventory>().UnEquipItem1(firstItem);
                //                           }
                //if you are dragging an item from the equipmentsystem to the inventory and they are not from the same itemtype they do not get swapped.
                //                             else if (oldSlot.transform.parent.parent.GetComponent<EquipmentSystem>() != null && firstItem.itemType != secondItem.itemType)
                //                           {
                //                             firstItemGameObject.transform.SetParent(oldSlot.transform);
                //                           firstItemRectTransform.localPosition = Vector3.zero;
                //                     }
                //swapping for the rest of the inventorys
                //                              else if (oldSlot.transform.parent.parent.GetComponent<EquipmentSystem>() == null)
                //                            {
                //                                  firstItemGameObject.transform.SetParent(secondItemGameObject.transform.parent);
                //                                secondItemGameObject.transform.SetParent(oldSlot.transform);
                //                                 secondItemRectTransform.localPosition = Vector3.zero;
                //                                 firstItemRectTransform.localPosition = Vector3.zero;
                //                           }
                //                     }

//                        }
//                  }
//                else
//                  {
//                      if (newSlot.tag != "Slot" && newSlot.tag != "ItemIcon")
//                      {
//                          firstItemGameObject.transform.SetParent(oldSlot.transform);
//                          firstItemRectTransform.localPosition = Vector3.zero;
//                    }
//                      else
//                    {
//                         firstItemGameObject.transform.SetParent(newSlot.transform);
//                        firstItemRectTransform.localPosition = Vector3.zero;

                //                      if (newSlot.transform.parent.parent.GetComponent<EquipmentSystem>() == null && oldSlot.transform.parent.parent.GetComponent<EquipmentSystem>() != null)
                //                        oldSlot.transform.parent.parent.GetComponent<Inventory>().UnEquipItem1(firstItem);
                //              }
                //             }

                //       }


                //     }

                //       else
                //       {
                //         GameObject firstItemGameObject = this.gameObject;

                //         RectTransform firstItemRectTransform = this.gameObject.GetComponent<RectTransform>();
                //         firstItemGameObject.transform.SetParent(oldSlot.transform);
                //      firstItemRectTransform.localPosition = Vector3.zero;


                //      GameObject dropItem = (GameObject)Instantiate(GetComponent<ItemOnObject>().item.itemModel);
                //      dropItem.AddComponent<PickUpItem>();
                //      dropItem.GetComponent<PickUpItem>().item = this.gameObject.GetComponent<ItemOnObject>().item;
                //      dropItem.transform.localPosition = GameObject.FindGameObjectWithTag("Player").transform.localPosition;
                //      inventory.OnUpdateItemList();
                //      if (oldSlot.transform.parent.parent.GetComponent<EquipmentSystem>() != null)
                //          inventory.GetComponent<Inventory>().UnEquipItem1(dropItem.GetComponent<PickUpItem>().item);
                //      Destroy(this.gameObject);
            }
        }
        inventory.OnUpdateItemList();
    }