Ejemplo n.º 1
0
    void LateUpdate()
    {
        // Camera Zoom
        cameraSize += Input.mouseScrollDelta.y * zoomSpeed;
        cameraSize  = Mathf.Clamp(cameraSize, cameraSizeMin, cameraSizeMax);
        Camera.main.orthographicSize = cameraSize;

        // Camera Movement
        for (int i = 5; i >= 1; i--)
        {
            if (Input.GetAxisRaw("J" + i + "Horizontal") != 0 || Input.GetAxisRaw("J" + i + "Vertical") != 0)
            {
                movement = new Vector3(Input.GetAxisRaw("J" + i + "Horizontal") * camera_speed, Input.GetAxisRaw("J" + i + "Vertical") * camera_speed, 0.0f);
            }
        }
        if (tilemapGround.WorldToCell(transform.position + movement).x > 0 && tilemapGround.WorldToCell(transform.position + movement).x < maxWidth)
        {
            transform.Translate(movement.x, 0, 0);
        }
        if (tilemapGround.WorldToCell(transform.position + movement).y > 0 && tilemapGround.WorldToCell(transform.position + movement).y < maxHeight)
        {
            transform.Translate(0, movement.y, 0);
        }
        movement = new Vector3();
    }
Ejemplo n.º 2
0
    public Vector3Int squareAroundPlayer(Vector2 dimensions)
    {
        List <Vector3Int> cells = new List <Vector3Int>();

        Vector3Int BL = Ground.WorldToCell(Camera.main.transform.position - (Vector3)dimensions / 2);
        Vector3Int TR = Ground.WorldToCell(Camera.main.transform.position + (Vector3)dimensions / 2);

        for (int y = BL.y; y <= TR.y; y++)
        {
            for (int x = BL.x; x <= TR.x; x++)
            {
                if ((BL.x == x || BL.y == y || TR.x == x || TR.y == y) && !WallMap.HasTile(Vector3Int.right * x + Vector3Int.up * y) && Ground.HasTile(Vector3Int.right * x + Vector3Int.up * y))
                {
                    cells.Add(Vector3Int.up * y + Vector3Int.right * x);
                }
            }
        }
        return(cells[Random.Range(0, cells.Count)]);
    }
Ejemplo n.º 3
0
    public void initialisationDesVars()
    {
        mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
        characterPos       = GameObject.FindGameObjectWithTag("Player").transform.position;
        characterPos.y    += GameObject.FindGameObjectWithTag("Player").transform.localScale.y / 2;
        scriptGen          = GameObject.FindGameObjectWithTag("FrontGround").transform.parent.GetComponent <PlanetGenerator>();
        UnityEngine.Tilemaps.Tilemap world = GameObject.FindGameObjectWithTag("FrontGround").GetComponent <UnityEngine.Tilemaps.Tilemap>();
        v          = world.WorldToCell(mouseWorldPosition);
        vCharacPos = world.WorldToCell(characterPos); // Used for collisions when creating a block
        distMax    = Vector2.Distance(mouseWorldPosition, characterPos);

        if ((v.x == vCharacPos.x - 1 || v.x == vCharacPos.x) &&
            (v.y == vCharacPos.y - 2 || v.y == vCharacPos.y - 1 || v.y == vCharacPos.y || v.y == vCharacPos.y + 1))
        {
            canCreate = false;
        }
        else
        {
            canCreate = true;
        }
    }
Ejemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        float x = 0;
        float y = 0;

        if (Input.GetKey(KeyCode.W))
        {
            y += 1;
        }
        if (Input.GetKey(KeyCode.S))
        {
            y -= 1;
        }
        if (Input.GetKey(KeyCode.A))
        {
            x -= 1;
        }
        if (Input.GetKey(KeyCode.D))
        {
            x += 1;
        }
        var newVelocity = new Vector2(x, y).normalized *speed;

        if (newVelocity.sqrMagnitude == 0 ^ velocity.sqrMagnitude > 0)
        {
            UpdateAnimation();
        }
        velocity = newVelocity;

        // Find out look direction
        if ((cameraInHand?.recordingstatus ?? Recorder.Recordingstatus.NO_RECORDING) == Recorder.Recordingstatus.NO_RECORDING)
        {
            var mousePos = cam.ScreenToWorldPoint(Input.mousePosition);
            mousePos = transform.worldToLocalMatrix.MultiplyPoint(mousePos);
            if (mousePos.x > mousePos.y)
            {
                if (-mousePos.x > mousePos.y)
                {
                    LookDirection = 2;
                }
                else
                {
                    LookDirection = 1;
                }
            }
            else
            {
                if (-mousePos.x > mousePos.y)
                {
                    LookDirection = 3;
                }
                else
                {
                    LookDirection = 0;
                }
            }
        }

        // Handling Input to pick up Camera
        if (Input.GetKeyDown(KeyCode.E))
        {
            if (cameraInHand)
            {
                if (!cameraInHand.gameObject.activeInHierarchy)
                {
                    // Try to pick up
                    List <Collider2D> colliders = new List <Collider2D>();
                    GetComponent <Collider2D>().OverlapCollider(new ContactFilter2D(), colliders);
                    var projector = colliders.Find(c => c.GetComponentInParent <Projector>() != null);
                    if (projector)
                    {
                        cameraInHand.SetLastRecording(projector.GetComponentInParent <Projector>().GetRecording());
                        Destroy(projector.transform.parent.gameObject);
                        cameraInHand.gameObject.SetActive(true);
                        cameraInHand.ShowLastRecordingStillframe();
                    }
                }
                else if (cameraInHand.GetComponent <Recorder>().GetLastRecording()?.Finished ?? true)
                {
                    if ((!floorTilemap?.GetTile(floorTilemap.WorldToCell(this.transform.position))?.name.Equals("gitter")) ?? true)
                    {
                        // Put it down and start
                        var p = Instantiate <Projector>(projectorPrefab, cameraInHand.transform.position, cameraInHand.transform.rotation);
                        p.StartProjection(cameraInHand.GetLastRecording());
                        cameraInHand.gameObject.SetActive(false);
                        cameraInHand.SetLastRecording(null);
                    }
                }
            }
        }

        // Handling Input to get back to Main Menu
        if (Input.GetKeyDown(KeyCode.Escape))
        {
            SceneManager.LoadScene(mainMenu, LoadSceneMode.Single);
        }

        // Updating UI to inform about pickup
        LevelUIBehaviour behav = cameraInHand.levelUIManagerObj.GetComponent <LevelUIBehaviour>();

        behav.DisplayPickupInfo(true);
        List <Collider2D> colliders2 = new List <Collider2D>();

        GetComponent <Collider2D>().OverlapCollider(new ContactFilter2D(), colliders2);
        var projector2 = colliders2.Find(c => c.GetComponentInParent <Projector>() != null);

        if (projector2)
        {
            behav.DisplayPickupInfo(true);
        }
        else
        {
            behav.DisplayPickupInfo(false);
        }
    }
    protected override void ComputeVelocity()
    {
        Vector2 move = Vector2.zero;

        move.x = Input.GetAxis("Horizontal");

        if (Input.GetButtonDown("Jump") && grounded)
        {
            velocity.y = jumpTakeOffSpeed;
            animator.SetBool("Jump", true);
        }
        else if (Input.GetButtonDown("Jump"))
        {
            if (velocity.y > 0)
            {
                velocity.y = velocity.y * 0.5f;
            }
            animator.SetBool("Jump", true);
        }
        else
        {
            animator.SetBool("Jump", false);
        }

        if (move.x != 0)
        {
            if (move.x < 0 && m_FacingRight)
            {
                m_FacingRight = false;
                Vector3 theScale = transform.GetChild(0).localScale;
                theScale.x *= -1;
                for (int i = 0; i < transform.childCount - 2; i++)
                {
                    transform.GetChild(i).localScale = theScale;
                }
            }
            if (move.x > 0 && !m_FacingRight)
            {
                m_FacingRight = true;
                Vector3 theScale = transform.GetChild(0).localScale;
                theScale.x *= -1;
                for (int i = 0; i < transform.childCount - 2; i++)
                {
                    transform.GetChild(i).localScale = theScale;
                }
            }
            animator.SetBool("Run", true);
        }
        else
        {
            animator.SetBool("Run", false);
        }

        /*animator.SetBool ("grounded", grounded);
         * animator.SetFloat ("velocityX", Mathf.Abs (velocity.x) / maxSpeed);*/

        targetVelocity = move * maxSpeed;

        if (!("Hub".Equals(SceneManager.GetActiveScene().name)) && (Input.GetButton("Fire1") || Input.GetMouseButtonDown(0)))
        {
            Vector3 mouseWorldPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            Vector3 characterPos       = this.transform.position;
            characterPos.y += this.transform.localScale.y / 2;
            float           distMax            = Vector2.Distance(mouseWorldPosition, characterPos);
            GameObject      frontground        = GameObject.FindGameObjectWithTag("FrontGround");
            PlanetGenerator scriptGen          = frontground.transform.parent.GetComponent <PlanetGenerator>();
            UnityEngine.Tilemaps.Tilemap world = frontground.GetComponent <UnityEngine.Tilemaps.Tilemap>();
            Vector3Int v = world.WorldToCell(mouseWorldPosition);
            v.x = ((v.x % scriptGen.planet.savedMapMatrix.GetLength(0)) + scriptGen.planet.savedMapMatrix.GetLength(0)) % scriptGen.planet.savedMapMatrix.GetLength(0);

            if (scriptGen.planet.savedMapMatrix[v.x, v.y] != 0 && scriptGen.planet.savedMapMatrix[v.x, v.y] < 100 && scriptGen.planet.savedMapMatrix[v.x, (v.y) + 1] < 100)
            {
                if (distMax <= 2f && v.y < scriptGen.maximalHeight - 10 && scriptGen.planet.savedMapMatrix[v.x, v.y] != scriptGen.unbreakableTileID && _database.getItemByID(scriptGen.planet.savedMapMatrix[v.x, v.y]).itemID > 0 &&
                    !_inventory.activeSelf && !_equipmentSystem.activeSelf && !_craftSystem.activeSelf)
                {
                    // creates a gameObject to be displayed
                    GameObject go = (GameObject)Instantiate(_database.getItemByTileBase(scriptGen.planet.tilesType[scriptGen.planet.savedMapMatrix[v.x, v.y]]).itemModel);
                    // adds script so it can be picked up
                    go.AddComponent <PickUpItem>();
                    go.GetComponent <PickUpItem>().item = _database.getItemByTileBase(scriptGen.planet.tilesType[scriptGen.planet.savedMapMatrix[v.x, v.y]]);
                    mouseWorldPosition.z       = 0;
                    go.transform.localPosition = mouseWorldPosition;
                    scriptGen.planet.savedMapMatrix[v.x, v.y] = 0;
                    //scriptGen.planet.savedMapHeight[v.x] -= 1;
                }
            }
        }
    }
Ejemplo n.º 6
0
    public void OnEndDrag(PointerEventData data)
    {
        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          firstItem  = rectTransform.GetComponent <ItemOnObject>().item;
                Item          secondItem = new Item();
                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)
                            {
                                //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
            {
                // position of the dropped item (i.e. gameObject)
                Vector3 mouse = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                mouse.z = 0;

                // position of the player
                Vector3 characPos = _player.transform.position;
                print("Mouse --> " + mouse);
                print("Characterpos --> " + characPos);
                float DistMaxtTest = Mathf.Abs(mouse.y - characPos.y);
                float distMax      = Vector2.Distance(mouse, characPos);
                print(distMax + " = " + DistMaxtTest);

                PlanetGenerator scriptGen          = GameObject.FindGameObjectWithTag("FrontGround").transform.parent.GetComponent <PlanetGenerator>();
                UnityEngine.Tilemaps.Tilemap world = GameObject.FindGameObjectWithTag("FrontGround").GetComponent <UnityEngine.Tilemaps.Tilemap>();

                // when dropping the item
                GameObject dropItem = (GameObject)Instantiate(GetComponent <ItemOnObject>().item.itemModel);
                dropItem.AddComponent <PickUpItem>();
                dropItem.GetComponent <PickUpItem>().item = this.gameObject.GetComponent <ItemOnObject>().item;

                if (dropItem.GetComponent <PickUpItem>().item.itemType == ItemType.FireWeapon1)
                {
                    if (_player.GetComponent <Animator>().GetBool("SwapToGun"))
                    {
                        GameObject.FindGameObjectWithTag("Hotbar").transform.GetChild(0).GetComponent <cursor>().UnequipWeapon();
                    }
                }
                if (dropItem.GetComponent <PickUpItem>().item.itemType == ItemType.FireWeapon2)
                {
                    if (_player.GetComponent <Animator>().GetBool("SwapToSub"))
                    {
                        GameObject.FindGameObjectWithTag("Hotbar").transform.GetChild(0).GetComponent <cursor>().UnequipWeapon();
                    }
                }
                if (dropItem.GetComponent <PickUpItem>().item.itemType == ItemType.MeleeWeapon)
                {
                    if (_player.GetComponent <Animator>().GetBool("SwapToKnife"))
                    {
                        GameObject.FindGameObjectWithTag("Hotbar").transform.GetChild(0).GetComponent <cursor>().UnequipWeapon();
                    }
                }
                if (distMax > 3f)
                {
                    if (mouse.x - characPos.x < 0)
                    {
                        mouse.x = characPos.x - 3f;
                    }
                    else if (mouse.x - characPos.x > 0)
                    {
                        mouse.x = characPos.x + 3f;
                    }
                }
                while (_database.getItemByID(scriptGen.planet.savedMapMatrix[world.WorldToCell(mouse).x, world.WorldToCell(mouse).y]).itemID > 0)
                {
                    mouse.y += 1;
                }

                dropItem.transform.position = mouse;
                // dropItem.tag = "DroppedObject";

                inventory.OnUpdateItemList();
                if (oldSlot.transform.parent.parent.GetComponent <EquipmentSystem>() != null)
                {
                    inventory.GetComponent <Inventory>().UnEquipItem1(dropItem.GetComponent <PickUpItem>().item);
                }
                Destroy(this.gameObject);
            }
        }
        inventory.OnUpdateItemList();
    }