- Home /
How To List Rooms (PUN 2)
Hi guys , I need to list the romos in my lobby scene. For now, this is the code I've used but I don't know why it isnt working. This is the correct way?
public override void OnRoomListUpdate(List<RoomInfo> roomList)
{
print(roomList.Count + " Rooms");
base.OnRoomListUpdate(roomList);
foreach (var Item in roomList)
{
RoomName = Item.Name;
PlayerAmount = Item.PlayerCount;
MaxPlayers = Item.MaxPlayers;
PhotonNetwork.Instantiate("RoomPrefab", transform.position, transform.rotation);
RoomPrefab.transform.Find("RoomName").GetComponent<Text>().text = RoomName;
RoomPrefab.transform.Find("PlayerInt").GetComponent<Text>().text = PlayerAmount.ToString();
if(MaxPlayers == 4)
{
GameObject.Find("IPlayerA").GetComponent<Image>().sprite = Four;
}
else if (MaxPlayers == 2)
{
GameObject.Find("IPlayerA").GetComponent<Image>().sprite = Two;
}
else if (MaxPlayers == 3)
{
GameObject.Find("IPlayerA").GetComponent<Image>().sprite = Three;
}
RoomPrefab.transform.SetParent(ScrollView.transform, false);
}
}
Answer by Develax · Jun 30, 2019 at 09:26 AM
The OnRoomListUpdate method is called when you successfully join a lobby. So, you have to call PhotonNetwork.JoinLobby() first.
This works, however, now when i try to call "PhotonNetwork.CreateRoom", it fails with:
"Operation CreateGame (227) not called because client is not connected or not ready yet, client state: JoiningLobby"
and, if i call it after finishing joining lobby i get this:
"CreateRoom failed. Client is on $$anonymous$$asterServer (must be $$anonymous$$aster Server for matchmaking)but not ready for operations (State: Disconnected). Wait for callback: OnJoinedLobby or OnConnectedTo$$anonymous$$aster."
And even after somehow having the state as connected, i get this?
CreateRoom failed. Client is on $$anonymous$$asterServer (must be $$anonymous$$aster Server for matchmaking)but not ready for operations (State: PeerCreated). Wait for callback: OnJoinedLobby or OnConnectedTo$$anonymous$$aster.
Try to call PhotonNetwork.LeaveLobby()
before creating a room.
Thanks Develax, I did try that, but error was worse, however, i have now got it workin.. thanks for the very quick response by the way : )
$$anonymous$$y first call was too soon after joining the lobby (i.e. directly after, and the status was "joining", 2nd attempt, I was getting a bit to excited with a button and clicking it before I had even connected, so it is all working now as expected : )
I'm trying the OnRoomListUpdate function, but I get the following error: No suitable method found to override. I use PUN 2 and Unity 2019.3.0f6 Here is my code:
public override void OnRoomListUpdate(List roomList) { Debug.Log("some code"); }
Have you inherited from $$anonymous$$onoBehaviourPunCallbacks
?
Your answer
Follow this Question
Related Questions
Photon PUN 2 Not working 1 Answer
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
I am developing a PUN Realtime project. I am having issues with players joining room. 0 Answers
Unity 2018 PUN 2 Error 0 Answers