Esempio n. 1
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            rightClickedPosition = Input.mousePosition;
        }
        if (Input.GetMouseButtonUp(0))
        {
            if (rightClickedPosition == Input.mousePosition)
            {
                SelectTile();
            }
        }
        if (Input.GetMouseButton(0))
        {
            MoveCameraHorizontally();
        }
        if (Input.GetAxis("Mouse Scroll") != 0)
        {
            MoveCameraVertically();
        }
        if (Input.GetMouseButton(1))
        {
            if (unitManager.selectedUnit != null)
            {
                Tile tile = GetTileWithRaycast();
                if (tile == leftClickedTile || tile == null)
                {
                    return;
                }
                leftClickedTile = tile;
                foreach (Tile n in unitManager.selectedUnit.path)
                {
                    if (n != selectedTile)
                    {
                        n.ResetColor();
                    }
                }
                if (tile == selectedTile)
                {
                    unitManager.selectedUnit.path.Clear();
                    return;
                }
                unitManager.selectedUnit.path =
                    map.GeneratePath(selectedTile, tile);
                unitManager.selectedUnit.DrawPath();
            }
        }

        if (Input.GetMouseButtonUp(1))
        {
            foreach (Tile n in unitManager.selectedUnit.path)
            {
                if (n != selectedTile)
                {
                    n.ResetColor();
                }
            }
            if (unitManager.selectedUnit.path.Count > 0)
            {
                unitManager.selectedUnit.Move();
                map.ResetTile(selectedTile);
                if (unitManager.selectedUnit.path.Count > 0)
                {
                    unitManager.AddUnitWithPath();
                }
            }
        }
    }