//Used to determine viable spawnpoints public void FindPossibleSpawnPoints(Tilemap floor) { List <Vector3> allowedSpawnPoints = new List <Vector3>(); //Look at floor tilemap BoundsInt floorBounds = floor.cellBounds; TileBase[] allFloorTiles = floor.GetTilesBlock(floorBounds); Debug.Log("Finding all possible spawnlocations for tilemap: " + floor.name); //Loop through all floor positions foreach (var pos in floor.cellBounds.allPositionsWithin) { //Only check positions that actually have a tile if (floor.HasTile(pos)) { bool isMissingNeighbours = false; //Check all neighbours of tile // X Y //-1, 0, 1 1,1,1 //-1, 0, 1 0,0,0 //-1, 0, 1 -1-1-1 for (int lx = -2; lx < 3; lx++) { for (int ly = -2; ly < 3; ly++) { Vector3Int newPos = pos; newPos.x += lx; newPos.y += ly; //Check if neibour is null if (!floor.HasTile(newPos)) { isMissingNeighbours = true; } } } //If no neighbours were missing add tile coordinates to list of allowed spawn points if (!isMissingNeighbours) { allowedSpawnPoints.Add(pos); } } } rooms[new Vector3(playerGridLocX, playerGridLocY)].possibleSpawnPoints = allowedSpawnPoints; if (isFirstRoom) { //Spawn some a chest w/ weapons to start with SpawnLoot(); //also spawn a tutorial npc npcSpawner.SpawnNPC("Tutorial", allowedSpawnPoints[Random.Range(0, allowedSpawnPoints.Count)]); isFirstRoom = false; } else { //Once positions are known instruct enemyspawner to instantiate enemies EnemySpawner.instance.SpawnEnemies(allowedSpawnPoints, enemyParent, new Vector3(playerGridLocX, playerGridLocY, 0)); EnemySpawner.instance.OnAllEnemiesCleared += DisableShadowWalls; } }