- Home /
Unity Photon - Multiple Lobbies
I might be asking the wrong question hence why I still have not found any answers yet. Basically my game model is of 5 levels. Each level has lots of players who are currently on that level. i.e. Level 3 players will be in the Level 3 group to have 1:1 matches with other level 3 players.
My Photon idea: I was thinking of creating 5 lobbies for each of the levels. And then for the 1:1 matches have the player automatically joined to a random player within their lobby. Am I on the right track or have I understood Photo completely wrong?
If this idea is correct then below is my current code:
void Start ()
{
PhotonNetwork.ConnectUsingSettings ("0.1");
}
// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
public void Connect()
{
PhotonNetwork.autoJoinLobby = false;
}
// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
void OnConnectedToMaster()
{
int index = PlayerPrefs.GetInt("PlayerLevel") - 1;
TypedLobby newLobby = new TypedLobby(index.ToString(), LobbyType.SqlLobby);
PhotonNetwork.JoinLobby(newLobby);
}
// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
void OnJoinedLobby()
{
PhotonNetwork.JoinRandomRoom ();
}
// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
void OnPhotonRandomJoinFailed()
{
PhotonNetwork.CreateRoom(null);
}
// <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><>
private PhotonView myPhotonView;
void OnJoinedRoom()
{
GameObject monster = PhotonNetwork.Instantiate("monsterprefab", Vector3.zero, Quaternion.identity, 0);
monster.GetComponent<myThirdPersonController>().isControllable = true;
myPhotonView = monster.GetComponent<PhotonView>();
}
Answer by tobiass · Feb 02, 2015 at 12:36 PM
The idea is correct. I didn't check your code in detail but it looks ok. In all cases, you join a specific lobby per level. When joined into a specific lobby, all join/create calls will refer to this lobby. The room is invisible in other lobbies.
You don't have to use a SQLLobby. If you don't need the more complex filtering it offers, simply use a default lobby type.
If you wanted to, you can also use JoinRandomRoom and CreateRoom overloads which have a TypedLobby parameter. So you don't even have to join a lobby to create or find rooms in it. You just pass that lobby as parameter.
Your answer
Follow this Question
Related Questions
Unity3D: Photon syncing physics events 0 Answers
increase unet hosts 0 Answers
PUN Update countOfPlayersOnMaster to all clients? 1 Answer
Photon variable synchronization 1 Answer
Unity3D Multiplayer with Photon 1 Answer