How to check if room is full and make new room in pun2

Options

hello everyone im making a multiplayer game and i create one room with 5 capacity if this room is full how to make a new one automatically.


Thank you

Answers

  • Tobias
    Options

    Have a look at the code in ConnectAndJoinRandom.cs and also check the Matchmaking doc page. That should explain it.

  • Anoniman
    Options

    my code is something like that but im trying to do 3 hours can you explain me how can i make it


    using System.Collections;

    using System.Collections.Generic;

    using UnityEngine;

    using UnityEngine.UI;

    using Photon.Pun;

    using Photon.Realtime;

    using TMPro;


    public class LobbyManager : MonoBehaviourPunCallbacks

    {

        [Header("---UI Screens---")]

        public GameObject roomUI;

        public GameObject connectUI;


        public bool isopenRoomList = false;


        [Header("---UI Text---")]

        public Text statusText;

        public Text connectingText;


        [Header("---UI InputFields---")]

        public InputField createRoom;

        public InputField joinRoom;


        [Header("SetName")]

        public InputField nametf;

        public Button setNameBtn;


        [Header("RoomList")]


        private List<RoomInfo> roomList;

        public GameObject tabRooms;

        public GameObject buttonRoom;



        void Awake()

        {

            PhotonNetwork.ConnectUsingSettings();


        }

       

        public override void OnConnectedToMaster()

        {

            connectingText.text = "Joining Lobby...";

            PhotonNetwork.JoinLobby();


        }

        public override void OnJoinedLobby()

        {

            connectUI.SetActive(false);

            roomUI.SetActive(true);

            statusText.text = "Joined To Lobby";

            PhotonNetwork.NickName = nametf.text;

            Debug.Log(PhotonNetwork.NickName);

        }


        public override void OnJoinedRoom()

        {

             PhotonNetwork.LoadLevel(3);

        }

        public override void OnDisconnected(DisconnectCause cause)

        {

            connectUI.SetActive(true);

            connectingText.text = "Disconnected... " + cause.ToString();

            roomUI.SetActive(false);

            StartCoroutine(MainReconnect());


        }


       

       

        #region ButtonClicks

        public void OnClick_PlayNow()

        {

            PhotonNetwork.JoinRandomRoom();

            statusText.text = "Creating Room... Please Wait...";

        }


        public void Room1()

        {

            RoomOptions roomOptions = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = 2 };

            if (PhotonNetwork.JoinOrCreateRoom("Oda1", roomOptions, TypedLobby.Default))

            {

                print("Create room successfully for Oda 1");

            }

            else

            {

                print("Create room failed");

            }

        }

        public void Room2()

        {

            RoomOptions roomOptions = new RoomOptions() { IsVisible = true, IsOpen = true, MaxPlayers = 2 };

            if (PhotonNetwork.JoinOrCreateRoom("Oda2", roomOptions, TypedLobby.Default))

            {

                print("Create room successfully for Oda 2");

            }

            else

            {

                print("Create room failed");

            }

        }


        private void ClearRoomList()

        {

            Transform content = tabRooms.transform.Find("Scroll View/Viewport/Content");

            foreach (Transform a in content) Destroy(a.gameObject);

        }


        public override void OnRoomListUpdate(List<RoomInfo> p_list)

        {

            roomList = p_list;

            ClearRoomList();


            Transform content = tabRooms.transform.Find("Scroll View/Viewport/Content");

            foreach (RoomInfo a in roomList)

            {

                GameObject newRoomButton = Instantiate(buttonRoom, content) as GameObject;


                newRoomButton.transform.Find("Name").GetComponent<TextMeshProUGUI>().text = a.Name;

                newRoomButton.transform.Find("Players").GetComponent<TextMeshProUGUI>().text = a.PlayerCount + " / " + a.MaxPlayers;

                newRoomButton.transform.Find("Giris").GetComponent<Button>().onClick.AddListener(Room1);

            }

            base.OnRoomListUpdate(roomList);

        }


    }