private void populateEnvironment() { for (int z = 0; z < grid.GetLength(1); z++) { for (int x = 0; x < grid.GetLength(0); x++) { if (x == 0 || z == 0 || x == grid.GetLength(0) - 1 || z == grid.GetLength(1) - 1 || grid[x, z] == 1) { if (Random.Range(0.0f, 1.0f) <= hiding_chance) { if (x != 0 && z != 0 && x != grid.GetLength(0) - 1 && z != grid.GetLength(1) - 1 && grid[x, z] == 1) { Vector3 spawn_vector = new Vector3(x, 0f, z); Vector3 rotateTowards = spawns.ClosestOpenVectorTo(spawn_vector); GameObject door_wall = Instantiate(hidingWall, spawn_vector, Quaternion.identity); door_wall.transform.SetParent(wall_parent.transform); door_wall.transform.LookAt(rotateTowards); } else { GameObject _wall = Instantiate(wall, new Vector3(x, 0f, z), Quaternion.identity); _wall.transform.SetParent(wall_parent.transform); } } else { GameObject _wall = Instantiate(wall, new Vector3(x, 0f, z), Quaternion.identity); _wall.transform.SetParent(wall_parent.transform); } } } } }