Joshua
Joshua

Reputation: 6241

Unity3D: PhotonNetwork.GetRoomList() cannot get any RoomInfo

I am trying to create a room UI. I built a copy to test if I can see any room. However, it does not received any room. Here is my code:

public class NetworkManager : Photon.MonoBehaviour
{
    public GameObject ScrollViewContent;
    public GameObject RoomListItem;
    public Text RoomNameInputField;
    void Start()
    {
        PhotonNetwork.ConnectUsingSettings("0.1");
    }

    void OnReceivedRoomListUpdate()
    {
        Debug.Log("OnReceivedRoomListUpdate");
    }

    void OnGUI()
    {
        Debug.Log("OnGUI");
        GUILayout.Label(PhotonNetwork.connectionStateDetailed.ToString());
        if (ScrollViewContent != null)
        {
            Debug.Log("ScrollViewContent");
            foreach (Transform child in ScrollViewContent.transform)
            {
                Debug.Log("Destroy");
                Destroy(child.gameObject);
            }
            foreach (RoomInfo game in PhotonNetwork.GetRoomList())
            {
                Debug.Log("RoomInfo");
                GameObject room = Instantiate(RoomListItem) as GameObject;
                room.GetComponentInChildren<Text>().text = game.name;
                room.transform.SetParent(ScrollViewContent.transform);
            }
            Debug.Log("ScrollViewContentEnd");
        }
    }


    public void CreateRoom()
    {
        if (!string.IsNullOrEmpty(RoomNameInputField.text))
            PhotonNetwork.CreateRoom(RoomNameInputField.text);
        //PhotonNetwork.CreateRoom(RoomNameInputField.text, new RoomOptions() { maxPlayers = 2,isVisible=true }, null);
    }
}

All of the public variables are set through inspector and console shows "ScrollViewContent" and "ScrollViewContentEnd" which means there should be no exception between them.

I have tried two ways to create room (both ways can create room successfully) and putting OnGUI() code in OnReceivedRoomListUpdate(). However, nothing show up, not even "RoomInfo" in console.

Is there something missed something in code?

Upvotes: 0

Views: 2069

Answers (1)

Joshua
Joshua

Reputation: 6241

I find out what the problem is. The default setting only join the server without join default lobby. Therefore, there is no room list.

Solution is to either create a lobby and join it or join the default lobby.

Upvotes: 1

Related Questions