The Photon Forum
is Closed Permanently.

After many dedicated years of service, we have made the decision to retire our Forum and switch to read-only: we´ve saved the best to last! Your search result can be found below. Plus, we offer support via these channels:

Try Our
Documentation

Please check if you can find an answer in our extensive documentation on PUN.

Join Us
on Discord

Meet and talk to our staff and the entire Photon-Community via Discord.

Read More on
Stack Overflow

Find more information on Stack Overflow (for Circle members only).

Write Us
an E-Mail

Feel free to send your question directly to our developers.

how to set max player to orginal lobby

hello_help_is_needed
2022-02-11 03:29:07

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().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???

Comments

Reetika_dev
2022-03-11 05:29:12

I am not sure about the lobby , but I have set maximum players for a room using this code, I hope it helps. Code will be similar to this -

int maxPlayers = 20;

public override void OnJoinedLobby()

{

base.OnJoinedLobby();

Debug.Log("We're in the lobby");

RoomOptions roomOptions = new RoomOptions();

print(maxPlayers);

print(System.Convert.ToByte(maxPlayers + 1));

roomOptions.MaxPlayers = System.Convert.ToByte(maxPlayers + 1);

PhotonNetwork.CreateRoom("RoomName" , roomOptions);

}

Back to top