Photon matchmaking

Hello all, I have currently started working on a multiplayer project using Photon Pun 2. I’m learning about the features and so far I learnt how to connect, disconnect, create room’s etc. So far when player clicks play, It instantiates the player and I’ve tried it an works. I’ve set a max amount of players allowed. What I want to do is make make a screen displaying how many players have joined and when the room is full, then it starts the match. So until the room isn’t full. The game won’t begin. How could I do this. If you need any scripts. Please ask and I’ll post some.

The master client needs to be be using OnPlayerEnteredRoom and then check if players in room matches max players. If so send an RPC or Event to everyone to start the game.

Hi toddkc, Thanks for your reply. I see where your heading. What I’ve done created the amount of players allowed

public override void OnJoinRandomFailed(short returnCode, string message)
    {
        base.OnJoinRandomFailed(returnCode, message);

        PhotonNetwork.CreateRoom(null, new RoomOptions { MaxPlayers = 2 });
    }

Then as you said to Use OnPlayerEnteredRoom. I created that function.
I’m confused how to check if the players in the room is equal to the max players?

I’ve tried something like this? Since I gotta go I’ll try it later but how does it seem to you

    public override void OnPlayerEnteredRoom(Photon.Realtime.Player newPlayer)
    {
        base.OnPlayerEnteredRoom(newPlayer);

        if(PhotonNetwork.PlayerList.Length == 2)
        {
            PhotonNetwork.LoadLevel(1);
        }
    }
1 Like

Also ensure this is only executed on one client by adding a PhotonNetwork.isMasterClient check.

Thanks for your reply, That’ll do, I’ll add PhotonNetwork.isMasterClient

Also, one other question if you don’t mind. At first I just used a cube and just used Input.GetAxis("Horizontal And vertical to see if the player is instantiated, and if the player can move in both of the screens. Now instead of using that. I used my own player and it’s movement scripts using joysticks. But all that happens is both players are instantiated but I can’t move? Why is this. It can’t have anything do do with the scripts because I’ve tested before.

Then if I just close the build app, the movement starts to work, but it’s all bugged and everything like that??

Hi, I am also looking for the same, is it working??

The “don’t begin game until room is full” part is going to be very specific to your game. You could start by setting the Time.timeScale to 0? Then make a UI text and add a component that implements the PUN OnPlayerJoinedRoom callback. When a player joins update the text with how many players are in the room. Then when the room is full have the master client send an event or RPC to the other players to start the game.

1 Like

What are you actually looking for, you gotta be more descriptive then that, I suggest you create a new post with your issue, that’ll help you a lot