public TileType?Apply(TileBase[] neighbors) { if (neighbors.Length < 9) { return(null); } // Get middle tile var tile = neighbors[(int)TilePositions.MIDDLE]; var tileType = TilemapHelper.GetTileTypeFromSpriteName(tile.name); // Check if the tile is already a wall if (tileType == TileType.WALL) { return(null); } // Check if the tile is not floor if (tileType != TileType.ROOM) { return(null); } var neighborTypes = new TileType[8]; int index = 0; int count = 0; foreach (var neighbor in neighbors) { if (count != (int)TilePositions.MIDDLE) { neighborTypes[index] = TilemapHelper.GetTileTypeFromSpriteName(neighbor.name); index++; } count++; } if (TilemapHelper.IsNextToType(neighborTypes, TileType.CORRIDOR)) { return(TileType.WALL); } return(null); }