Exemplo n.º 1
0
    public void OnEndDrag(PointerEventData eventData)
    {
        if (!isInDeck)
        {
            PointerEventData pointerData = new PointerEventData(EventSystem.current);

            pointerData.position = Input.mousePosition; // use the position from controller as start of raycast instead of mousePosition.

            List <RaycastResult> results = new List <RaycastResult>();
            EventSystem.current.RaycastAll(pointerData, results);

            if (results.Exists(e => e.gameObject.GetComponent <InventorySlot>()))
            {
                foreach (var thing in results)
                {
                    var slot = thing.gameObject.transform.GetComponent <InventorySlot>();
                    if (slot != null && !slot.locked)
                    {
                        cloneToPlace.transform.position = slot.transform.position + (Vector3.forward * -.1f);
                        cloneToPlace.AddToDeck(slot);
                    }
                    else if (slot != null && slot.locked)
                    {
                        Destroy(cloneToPlace.gameObject);
                    }
                }
            }
            else
            {
                Destroy(cloneToPlace.gameObject);
            }
        }
        else
        {
            RemoveFromDeck();

            Destroy(gameObject);
        }

        cloneToPlace = null;
    }