- Home /
max players in orginal room
i want to set an already made max amount of players how do i do that and here is my code
using UnityEngine;
using Photon.Pun;
using Photon.Realtime;
public class RoomManager : MonoBehaviourPunCallbacks
{
[Tooltip("The maximum number of players per room. When a room is full, it can't be joined by new players, and so new room will be created")]
[SerializeField]
private byte maxPlayersPerRoom = 4;
byte MaxPlayers = 4;
public string roomName = "Room";
// Start is called before the first frame update
void Start()
{
PhotonNetwork.ConnectUsingSettings();
Debug.Log("Connecting..");
}
public override void OnConnectedToMaster()
{
Debug.Log("Connected to server");
base.OnConnectedToMaster();
PhotonNetwork.JoinLobby();
}
public override void OnJoinedLobby()
{
base.OnJoinedLobby();
Debug.Log("We're in the lobby");
PhotonNetwork.JoinOrCreateRoom(roomName, null, null);
}
public override void OnJoinRandomFailed(short returnCode, string message)
{
Debug.Log("PUN Basics Tutorial/Launcher:OnJoinRandomFailed() was called by PUN. No random room available, so we create one.\nCalling: PhotonNetwork.CreateRoom");
// #Critical: we failed to join a random room, maybe none exists or they are all full. No worries, we create a new room.
RoomOptions Options = new RoomOptions();
PhotonNetwork.CreateRoom(null, new RoomOptions { MaxPlayers = maxPlayersPerRoom });
}
public override void OnJoinedRoom()
{
base.OnJoinedRoom();
GetComponent<PlayerSpawner>().SpawnPlayer();
Debug.Log("We're connected and in a room!");
}
}
so what I mean is that it connects to a lobby but that lobby doesn't have a max to how many player can be in it
how can i fix it???