How to check and join a room with a specific name
Options
I created a room with a name, and I would like to join this room
0
Comments
-
Hi @AlexLukanga,
Thank you for choosing Photon!
Just call JoinRoom(roomName) and implement callbacks for success & failure (e.g. game is full, game is closed, game does not exist).
There is also JoinOrCreate method which attempts to join then, if the room is not found, creates it.0 -
I just creted a funtion that check room but i'm geting this error
Assets\Scripts\Connect.cs(66,45): error CS7036: There is no argument given that corresponds to the required formal parameter 'typedLobby' of 'PhotonNetwork.GetCustomRoomList(TypedLobby, string)'using Photon.Pun; using Photon.Realtime; using System.Collections; using System.Collections.Generic; using TMPro; using UnityEngine; public class Connect : MonoBehaviourPunCallbacks { [SerializeField] private GameObject connectingPanel; [SerializeField] private GameObject createRoomPanel; [SerializeField] private GameObject startGamePanel; [SerializeField] private GameObject adversaryPanel; [SerializeField] private TextMeshProUGUI mainServerText; [SerializeField] private TextMeshProUGUI mainUserText; [SerializeField] private TextMeshProUGUI otherServerText; [SerializeField] private TextMeshProUGUI otherUserText; [SerializeField] private TextMeshProUGUI infoServerText; private bool isConnected = false; private const string gameVersion = "0.1"; private const int maxPlayersPerRoom = 2; [SerializeField] private int correntNumber = 0; [SerializeField] private int playerCount = 0; [SerializeField] private string roomName; private void Awake() => PhotonNetwork.AutomaticallySyncScene = true; public void Update() { playerCount = PhotonNetwork.CurrentRoom.PlayerCount; roomName = mainServerText.text; } public void CreateServer() { createRoomPanel.SetActive(false); connectingPanel.SetActive(true); isConnected = true; PhotonNetwork.ConnectUsingSettings(gameVersion); } public override void OnConnectedToMaster() { if(playerCount == 0 && correntNumber == 0) { CreateARoom(); } } public void CreateARoom() { RoomOptions roomOptions = new RoomOptions(); roomOptions.IsVisible = false; roomOptions.MaxPlayers = 2; PhotonNetwork.CreateRoom(roomName, roomOptions, TypedLobby.Default); Debug.Log("You create room: " + roomName); correntNumber = 1; } public void JoinARoom() { RoomInfo[] roomInfo = PhotonNetwork.GetCustomRoomList(; RoomInfo[] rooms = roomInfo; for (int i = 0; i < rooms.Length; i++) { if (rooms[i].Name == roomName) { Debug.Log("This room exists !"); PhotonNetwork.JoinRoom(roomName); Debug.Log("You join in the room: " + roomName); correntNumber = 2; } } } public override void OnJoinedRoom() { if (playerCount != maxPlayersPerRoom) { infoServerText.text = "Waiting for the opponent..."; } else { infoServerText.text = "You are connected!"; if (correntNumber == 1) { connectingPanel.SetActive(false); startGamePanel.SetActive(true); } else if (correntNumber == 2) { connectingPanel.SetActive(false); adversaryPanel.SetActive(true); } } Debug.Log(playerCount.ToString()); } }
0