Documentation
Ask or search…
K
Links

Join a Lobby

With the list of existing rooms displayed, the Join Lobby button allows players to enter a specific room
  • Create function JoinLobbyById in MenuSceneManager.cs :
public async void JoinLobbyByLobbyId(string lobbyId)
{
/* Start Client when Join Lobby as client */
// NetworkManager.Singleton.StartClient();
LobbyManager.Instance.CurrentLobby = await LobbyService.Instance.JoinLobbyByIdAsync(lobbyId);
SetupDataAfterJoinLobby();
}
public void SetupDataAfterJoinLobby()
{
Debug.Log(
$"Join lobby Id {LobbyManager.Instance.CurrentLobby.Id} has code {LobbyManager.Instance.CurrentLobby.LobbyCode}");
LobbyManager.Instance.isLobbyHost = false;
_roomCodeLobbyTextField.text = LobbyManager.Instance.CurrentLobby.LobbyCode;
UpdateStatusText();
LobbyManager.Instance.isSetInitPlayerDataObject = false;
}
For each room item in the existing rooms list: Add onClick JoinRoom when a player clicks the Join Lobby button :
public async void ListLobbies()
{
// ...
lobbyItem.SetData("#" + (i + 1), lobby.Id, lobby.LobbyCode, lobby.Name);
lobbyItem.SetOnClickJoin(OnClickJoinLobby);
listLobbies.Add(lobbyItem);
// ...
}
public void OnClickJoinLobby(string lobbyId)
{
if (LobbyManager.Instance.CurrentLobby is null)
JoinLobbyByLobbyId(lobbyId);
}