public void Update()
    {
        playerUnits.RemoveAll(item => item == null); // remove destroyed units
        if (playerUnits.Count == 0)
        {
            currentlySelectedUnit = -1;
        }

        if (!calledRangeDisplayHelperOnce)
        {
            DisplayReachableTilesForCurrentUnit();
            calledRangeDisplayHelperOnce = true;
        }

        // Change unit selection
        if (Input.GetMouseButtonDown(0))
        {
            var clickedCell     = GetTileClick();
            var unitsOnThatCell = playerUnits.Where(unit => unit.TilePosition == clickedCell && unit.ActionPoints > 0).ToList();
            if (unitsOnThatCell.Count > 0)
            {
                currentlySelectedUnit = playerUnits.IndexOf(unitsOnThatCell.First());

                var currentUnit = playerUnits.Find(a => a == unitsOnThatCell.First());

                DisplayReachableTilesForCurrentUnit();

                Debug.Log("Changed selection to " + currentUnit.name + ", " + currentUnit.ActionPoints + " AP left");
                audioController.PlayUnitChooseSound();
            }
        }
        // Movement
        else if (Input.GetMouseButtonDown(1))
        {
            if (playerUnits.Count > 0)
            {
                var clickedCell        = GetTileClick();
                var clickedTile        = (AbstractGameTile)tilemap.GetTile(clickedCell);
                var currentUnit        = playerUnits[currentlySelectedUnit];
                var reachableTiles     = TilemapHelper.FindReachableTiles(currentUnit.TilePosition, currentUnit.ActionPoints, tilemap);
                var reachableFireTiles = TilemapHelper.FindReachableFireTiles(currentUnit.TilePosition, currentUnit.ActionPoints, tilemap);

                int cellInFringe     = -1;
                int fireCellInFringe = -1;
                Tuple <Vector3Int, int> targetTile     = null;
                Tuple <Vector3Int, int> targetFireTile = null;
                for (int fringe = 0; fringe < reachableTiles.Count; fringe++)
                {
                    var reachableTile = reachableTiles[fringe].Where(tile => tile.Item1 == clickedCell).ToList();
                    if (reachableTile.Count > 0)
                    {
                        targetTile   = reachableTile.First();
                        cellInFringe = fringe;
                        break;
                    }
                }
                for (int fringe = 0; fringe < reachableFireTiles.Count; fringe++)
                {
                    var reachableFireTile = reachableFireTiles[fringe].Where(tile => tile.Item1 == clickedCell).ToList();
                    if (reachableFireTile.Count > 0)
                    {
                        targetFireTile   = reachableFireTile.First();
                        fireCellInFringe = fringe;
                        break;
                    }
                }

                if (cellInFringe >= 0 && !playerUnits.Any(unit => unit.TilePosition == clickedCell) && (currentUnit.ActionPoints >= targetTile?.Item2 || currentUnit.ActionPoints >= targetFireTile?.Item2))
                {
                    Debug.Log("Moved unit " + currentUnit.name + " from " + currentUnit.TilePosition + " to " + clickedCell + ", costing " + targetTile.Item2 + ". There are " + (currentUnit.ActionPoints - targetTile.Item2) + " AP left.");
                    currentUnit.ActionPoints            -= targetTile.Item2;
                    currentUnit.TilePosition             = clickedCell;
                    currentUnit.ObjectTransform.position = new Vector3(tilemap.CellToWorld(clickedCell).x, 0, tilemap.CellToWorld(clickedCell).z);

                    audioController.PlayUnitMoveSound();

                    DisplayReachableTilesForCurrentUnit();

                    // Select next unit, no AP remaining
                    ChooseNextUnitOrGoToNextRound();
                }
            }
        }
        else if (Input.GetKeyDown(KeyCode.E))
        {
            ExecuteAction(playerUnits[currentlySelectedUnit].UnitActions[0], playerUnits[currentlySelectedUnit].UnitType, playerUnits[currentlySelectedUnit]);
        }
        // Skip to next turn
        else if (Input.GetKeyDown("space"))
        {
            //currentlySelectedUnit = 0;
            UpdateTiles();
        }

        if (currentlySelectedUnit != -1)
        {
            UnitSelector.transform.position = playerUnits[currentlySelectedUnit].transform.position;
        }
        else
        {
            Destroy(UnitSelector);
        }
    }
    public void ExecuteAction(Tuple <string, int, string> action, UnitType unitType, AbstractUnit unit)
    {
        if (action != null)
        {
            switch (action.Item1)
            {
            case "dig_trench":
            {
                if (unitType != UnitType.Digger)
                {
                    return;
                }

                var standingOn = (AbstractGameTile)tilemap.GetTile(unit.TilePosition);
                if (unit.ActionPoints >= action.Item2 && standingOn.TileProperties.IsMovable && !standingOn.TileProperties.IsGoal && standingOn.TileProperties.IsFlammable)
                {
                    tilemap.SetTile(unit.TilePosition, Resources.Load("TrenchTile", typeof(TrenchTile)) as TrenchTile);
                    unit.ActionPoints -= action.Item2;
                    DisplayReachableTilesForCurrentUnit();

                    audioController.PlayDigTrenchSound();

                    Debug.Log("Placed trench on tile " + unit.TilePosition + ", costing " + action.Item2 + " APs. There are " + (unit.ActionPoints) + " AP left.");
                }
            }
            break;

            case "extinguish_fire":
            {
                if (unitType != UnitType.FireTruck && unitType != UnitType.Firefighter)
                {
                    return;
                }

                var extinguished     = 0;
                var fireTilesInRange = TilemapHelper.FindReachableFireTiles(unit.TilePosition, unit.ReachableFire, tilemap);
                if (unit.ActionPoints >= action.Item2)
                {
                    for (int i = 1; i < fireTilesInRange.Count; i++)
                    {
                        foreach (var tile in fireTilesInRange[i])
                        {
                            tilemap.SetTile(tile.Item1, Resources.Load("BurntTile", typeof(BurntTile)) as BurntTile);
                            extinguished++;
                        }
                    }

                    if (extinguished > 0)
                    {
                        unit.ActionPoints -= action.Item2;
                        audioController.PlayExtinguishFireSound();
                        DisplayReachableTilesForCurrentUnit();
                    }
                }
            }
            break;
            }
        }

        ChooseNextUnitOrGoToNextRound();
    }