// Flood fill technique to check house size and find the outer line for wall checking public static bool FloorFloodFill(Vector2Int firstTile, TileBase[] wallTiles, TileBase[] floorTiles, TileBase[] doorTiles, Tilemap tilemap, /*Temporary Value*/ TileBase whiteTile, Tilemap houseTilemap, TileBase[] roofTiles) { // Stack that expands and shrinks as you find more elements Stack <Vector2Int> existFloor = new Stack <Vector2Int>(); // Temporary stack that holds checked floor coordinates Stack <Vector2Int> checkedFloor = new Stack <Vector2Int>(); Stack <TileBase> floorTilesStack = new Stack <TileBase>(floorTiles); existFloor.Push(firstTile); while (existFloor.Count > 0) { Vector2Int pos = existFloor.Pop(); if (!checkedFloor.Contains(new Vector2Int(pos.x, pos.y))) { for (int y = -1; y <= 1; y++) { for (int x = -1; x <= 1; x++) { if (floorTilesStack.Contains(tilemap.GetTile(new Vector3Int(pos.x + x, pos.y + y, 0)))) { existFloor.Push(new Vector2Int(pos.x + x, pos.y + y)); } } } checkedFloor.Push(new Vector2Int(pos.x, pos.y)); } } // returns true if building is surrounded by walls Vector2Int[] wallPos = HouseBuilding.FloorEdgeFound(checkedFloor, wallTiles, floorTiles, doorTiles, tilemap); if (wallPos.Length <= 0) { return(false); } Debug.Log("Still going!"); // bool to make sure a door is built // if house is missing a door it won't build bool doorCheck = false; //Checks that a door is placed to be able to enter the house for (int i = 0; i < wallPos.Length; i++) { for (int j = 0; j < doorTiles.Length; j++) { if (tilemap.GetTile(new Vector3Int(wallPos[i].x, wallPos[i].y, 0)) == doorTiles[j]) { doorCheck = true; } } } // returns false and won't build the home if door isnt recognized if (!doorCheck) { return(false); } Stack <Vector2Int> roofPos = BuildWalls(wallTiles, doorTiles, floorTiles, wallPos, tilemap, whiteTile, houseTilemap); GetRoofTilePosition(wallTiles, floorTiles, roofTiles, tilemap, /* TEMPORARY VARIABLE */ whiteTile, houseTilemap, roofPos); return(true); }