Beispiel #1
0
    public bool IsNearEmptySlot(GameObject targetObject, ScrSlot emptySlot)
    {
        bool isNear = false;

        ScrBody scrBody = targetObject.GetComponent <ScrBody>();

        if (scrBody.orderX == emptySlot.GetOrderX())
        {
            int gap = scrBody.orderY - emptySlot.GetOrderY();
            if (gap == 1 || gap == -1)
            {
                isNear = true;
            }
        }
        else if (scrBody.orderY == emptySlot.GetOrderY())
        {
            int gap = scrBody.orderX - emptySlot.GetOrderX();
            if (gap == 1 || gap == -1)
            {
                isNear = true;
            }
        }
        else
        {
            isNear = false;
        }

        return(isNear);
    }
Beispiel #2
0
    public void MoveToEmptySlot(GameObject targetObject, ScrSlot emptySlot)
    {
        if (IsNearEmptySlot(targetObject, emptySlot))
        {
            Debug.Log("IsNearEmptySlot");
            Vector2 tempPosition = targetObject.transform.position;

            targetObject.transform.position = emptySlot.GetSlotPosition();
            emptySlot.SetSlotPosition(tempPosition.x, tempPosition.y);

            int tempOrderX = targetObject.GetComponent <ScrBody>().orderX;
            int tempOrderY = targetObject.GetComponent <ScrBody>().orderY;

            targetObject.GetComponent <ScrBody>().orderX = emptySlot.GetOrderX();
            targetObject.GetComponent <ScrBody>().orderY = emptySlot.GetOrderY();

            emptySlot.SetOrder(tempOrderX, tempOrderY);
        }
    }