Example #1
0
    void OnMouseDown()
    {
        Vector2 rawPos = CalculateWorldPointOfMouseClick();

        roundedPos = SnapToGrid(rawPos);

        foreach (Player player in players)
        {
            if (player.IsMoving)
            {
                currentPlayer         = player;
                currentPlayerPosition = player.transform.position;
                if (moveChecker.IsFree(roundedPos.x, roundedPos.y))

                {
                    int m;
                    int n1 = Mathf.Abs((int)player.transform.position.x - (int)roundedPos.x);
                    int n2 = Mathf.Abs((int)player.transform.position.y - (int)roundedPos.y);
                    if (n1 > n2)
                    {
                        m = n1;
                    }
                    else if (n1 < n2)
                    {
                        m = n2;
                    }
                    else
                    {
                        m = n2;
                    }
                    moving = true;
                    player.SetAniBool("isWalking", true);
                    player.moves -= m;
                    moveChecker.ClearFree();
                    GameObject[] boxes = GameObject.FindGameObjectsWithTag("box");
                    foreach (GameObject box in boxes)
                    {
                        Destroy(box);
                    }
                }
            }
        }
    }