Пример #1
0
    // Update is called once per frame
    void Update()
    {
        var gdm = GameObject.FindObjectOfType <GameDataManager>();

        if (Input.GetMouseButton(0))
        {
            if (!draggin && item == null && slot != null)
            {
                if (slot.Item != null)
                {
                    gdm.Player.Inventory.Add(slot.Item);
                    lc.addItemToInventory(slot.Item);
                    slot.setItem(null);
                    slot = null;
                }
            }
            else
            {
                Debug.Log("draggin");
                draggin = true;
                if (!justdown && item != null)
                {
                    //set drag image icon here
                    dragImage.sprite = gdm.itemSprites[item.Art];
                    //-----
                    justdown          = true;
                    dragImage.enabled = true;
                }
                dragImage.GetComponent <RectTransform>().position = Input.mousePosition;
            }
        }
        else if (!Input.GetMouseButton(0))
        {
            dragImage.enabled = false;
            draggin           = false;

            if (slot != null && item != null)
            {
                if (slot.type == item.Type)
                {
                    //slot item
                    if (slot.Item != null)
                    {
                        gdm.Player.Inventory.Add(slot.Item);
                        lc.addItemToInventory(slot.Item);
                    }
                    slot.setItem(item);
                    slotItem(gdm.Player, item);
                    GameObject.Destroy(itemObject);
                    removeFromInventory(gdm, item);
                    item       = null;
                    itemObject = null;
                    Debug.Log("slotted item");
                }
                else
                {
                    //failed to slot play sound?
                    item       = null;
                    itemObject = null;
                }
            }
            else if (item != null && onTrash)
            {
                //throw item on trash
                Debug.Log("trashed item");
                GameObject.Destroy(itemObject);
                removeFromInventory(gdm, item);
                gdm.addPickup(item);
                textDisplay.showText(item.DropText);
                item       = null;
                itemObject = null;
            }
            else if (item != null)
            {
                //do nothing with item
                //        Debug.Log("did nothing with item");
            }
            justdown = false;
        }
    }