How would I go about this approach...

Hey, I'm quite new to networking and PUN.

I was just wondering for some direction.
I've got lobbies set up and rooms created, and that all works fine.
But what I would like advice on, is when people join a room, Instead of spawning straight in and playing the game,
How would i go about making like an additional "lobby" type thing, which will basically just all the connected people and have like a "Ready" button.
Because for my game to work, it needs at least 2 players, and as it is a timed game they also need to spawn at the same time, when 2 players are ready.

I'll try to explain a little bit better.

Guy A : Creates a room and joins it. He is then welcomed by a menu which shows all the players in the room. (This I can do).
I want the option so that next to each players names there will be a "ready" button.
Guy B: Joins the room and loads up the level. I want him also to be greeted be a menu which will show him and the other connected player on the menu (this i can do).

The thing I want guidance on, is so that both players can "Ready" their own button, see if the other player is ready, and then when they both are, do like a 5 seconds countdown and spawn them both.

I hope what i'm trying to say makes sense :P
Cheers for any help :)


  • Hi,

    Try set 'Ready' actor property when player presses 'Ready' button:
    PhotonNetwork.player.SetCustomProperties( new ExitGames.Client.Photon.Hashtable() { {"Ready", true}});

    In OnPhotonPlayerPropertiesChanged check 'Ready' property of each player. Iterate PhotonNetwork.playerList for that and take customProperties["Ready"] of every element.
  • Vadim,

    can you show a sample code in 'OnPhotonPlayerPropertiesChanged' ?
    im really confused how to iterate CustomProperties of each player in PhotonNetwork.playerList, ex: customProperties["Ready"]
  • Implement OnPhotonPlayerPropertiesChanged in script attached to object with PhotonView.
    OnPhotonPlayerPropertiesChanged doc:
    /// Called when custom player-properties are changed. Player and the changed properties are passed as object[].
    /// Since v1.25 this method has one parameter: object[] playerAndUpdatedProps, which contains two entries.
    /// [0] is the affected PhotonPlayer.
    /// [1] is the Hashtable of properties that changed.
    /// ...
    /// Example:<pre>
    /// void OnPhotonPlayerPropertiesChanged(object[] playerAndUpdatedProps) {
    /// PhotonPlayer player = playerAndUpdatedProps[0] as PhotonPlayer;
    /// Hashtable props = playerAndUpdatedProps[1] as Hashtable;
    /// //...
    /// }
    Iterating players would be:
    for (int i = 0; i &lt; PhotonNetwork.playerList.Length; i++)
                PhotonPlayer player = PhotonNetwork.playerList&#91;i&#93;;
                var ready = player.customProperties&#91;"Ready"&#93;
  •, Vadim
    what you think about this?
    public List&lt;PhotonPlayer&gt; playerReady = new List&lt;PhotonPlayer&gt;();
    	void OnPhotonPlayerPropertiesChanged (object&#91;&#93; obj)
    		PhotonPlayer player = obj&#91;0&#93; as PhotonPlayer;
    		ExitGames.Client.Photon.Hashtable props = obj&#91;1&#93; as ExitGames.Client.Photon.Hashtable;
    		foreach(PhotonPlayer p in PhotonNetwork.playerList)
    			if(props.ContainsKey("READY") && player == p)
    				if(p.customProperties.ContainsKey("READY") && p.customProperties.ContainsValue(true))
    					playerReady .Add(p);
    any wrong about it? i just take an int as ReadyCounter from playerReady.Count ;)
  • I think that if you test each player against given player inside loop (player == p), you do not need loop at all. Just apply loop body to given player.
  • no need "player ==p"?
    can you send me a code as what you mean about it?
    help me pls, thanks Vadim
  • foreach(PhotonPlayer p in PhotonNetwork.playerList) {
    if(player == p) {
    // do something with 'player'
    is the same as just
    // do something with 'player'

    If you do not see anything wrong and code works, just leave it as is.
    May be I'm wrong :)