private bool ConnectToSomething(BaseRoom room, Vector2Int p) { List <Vector2Int> neighbours = new List <Vector2Int>(); BaseRoom neighbourRoom = GetRoomAtPosition(p.x, p.y + 1); if (room.HasDoor(Door.Up) && neighbourRoom != null && neighbourRoom.HasDoor(Door.Down)) { neighbours.Add(Vector2Int.up); } neighbourRoom = GetRoomAtPosition(p.x, p.y - 1); if (room.HasDoor(Door.Down) && neighbourRoom != null && neighbourRoom.HasDoor(Door.Up)) { neighbours.Add(Vector2Int.down); } neighbourRoom = GetRoomAtPosition(p.x + 1, p.y); if (room.HasDoor(Door.Right) && neighbourRoom != null && neighbourRoom.HasDoor(Door.Left)) { neighbours.Add(Vector2Int.right); } neighbourRoom = GetRoomAtPosition(p.x - 1, p.y); if (room.HasDoor(Door.Left) && neighbourRoom != null && neighbourRoom.HasDoor(Door.Right)) { neighbours.Add(Vector2Int.left); } if (neighbours.Count == 0) { return(false); } Vector2Int selectedDirection = neighbours[Random.Range(0, neighbours.Count)]; BaseRoom selectedRoom = GetRoomAtPosition(p.x + selectedDirection.x, p.y + selectedDirection.y); if (selectedDirection == Vector2Int.up) { room.SetDoorState(Door.Up, false); selectedRoom.SetDoorState(Door.Down, false); } else if (selectedDirection == Vector2Int.down) { room.SetDoorState(Door.Down, false); selectedRoom.SetDoorState(Door.Up, false); } else if (selectedDirection == Vector2Int.right) { room.SetDoorState(Door.Right, false); selectedRoom.SetDoorState(Door.Left, false); } else if (selectedDirection == Vector2Int.left) { room.SetDoorState(Door.Left, false); selectedRoom.SetDoorState(Door.Right, false); } return(true); }