void Spawn() { if (!spawned) { GameObject room; if (openingDirection == 1) { if (templates.maxRooms > 1) { rand = Random.Range(0, templates.bottomRooms.Length); room = (GameObject)Instantiate(templates.bottomRooms [rand], transform.position, Quaternion.identity); } else { room = (GameObject)Instantiate(templates.bottom, transform.position, Quaternion.identity); } } else if (openingDirection == 2) { if (templates.maxRooms > 1) { rand = Random.Range(0, templates.topRooms.Length); room = (GameObject)Instantiate(templates.topRooms [rand], transform.position, Quaternion.identity); } else { room = (GameObject)Instantiate(templates.top, transform.position, Quaternion.identity); } } else if (openingDirection == 3) { if (templates.maxRooms > 1) { rand = Random.Range(0, templates.leftRooms.Length); room = (GameObject)Instantiate(templates.leftRooms [rand], transform.position, Quaternion.identity); } else { room = (GameObject)Instantiate(templates.left, transform.position, Quaternion.identity); } } else if (openingDirection == 4) { if (templates.maxRooms > 1) { rand = Random.Range(0, templates.rightRooms.Length); room = (GameObject)Instantiate(templates.rightRooms [rand], transform.position, Quaternion.identity); } else { room = (GameObject)Instantiate(templates.right, transform.position, Quaternion.identity); } } else { room = new GameObject(); } room.transform.SetParent(templates.Rooms.transform); templates.rooms.Add(room); templates.restartTime(); templates.maxRooms--; spawned = true; } }