Exemplo n.º 1
0
    private InventorySquare FindClosestSquare()
    {
        float           minDistance = float.MaxValue;
        InventorySquare closest     = null;

        foreach (InventorySquare square in InventorySquare.Squares)
        {
            float distance = Vector2.Distance(square.Position, _rt.position);
            if (minDistance > distance)
            {
                closest     = square;
                minDistance = distance;
            }
        }

        return(closest);
    }
Exemplo n.º 2
0
    public void OnEndDrag(PointerEventData eventData)
    {
        Debug.Log("End drag");

        InventorySquare closest = FindClosestSquare();

        _set = true;

        if (Vector2.Distance(closest.Position, _rt.position) > _lockThreshold)
        {
            _rt.position = _startPos;
        }
        else
        {
            _rt.position = closest.transform.position;
        }
    }