Now to sync starting game?

Options
Hello. In my game there is "Waiting room" before starting the game. Then host can press button Start and everyone will load new level and play(room will be closed and not visible). But I found a problem... If host press button "Start" everyone load scene BUT game events doesn't happens on clients, only on host! (Like a Spawning players etc). But If I load scene from everyone in waiting room, game will work perfect! Load for everyone it if OnJoinedRoom and PlayerConnected call function which will start the game. (Host, and all clients will Start game, not only host). How can I fix it from button? How can I do a RPC in waiting room without PUN View?

Comments

  • Hi @RandomMan,

    when the 'Start' button gets clicked, do you use PhotonNetwork.LoadLevel(...) for loading the level and have PhotonNetwork.automaticallySyncScene set to true?

    Another way to start a game is using the room properties. You can set up a value which determines if the game is running. Whenever the MasterClient presses the 'Start' button, you can use something like this PhotonNetwork.room.SetCustomProperties(new Hashtable() { { "Ready", true } }); to start the game. This requires you having the callback OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged) implemented. There you can check, if the value "Ready" has been set to true. In this case, you can e.g. disable input blocks or turning of a panel which displays that the game is not ready.
  • RandomMan
    Options
    Hmm you saying very strange way. Can I add to players Pun view and do RPC?
  • RandomMan
    Options
    I have tryed your way and it's write me
    The best match for method OnPhotonCustomRoomPropertiesChanged has some invalid parameters

    My code:
    void OnPhotonCustomRoomPropertiesChanged(Hashtable propertiesThatChanged)
    {
    if (propertiesThatChanged == PhotonNetwork.room.CustomProperties["Start"] == true)
    {
    PhotonNetwork.LoadLevel(2);
    }
    }

    public void StartGame()
    {
    PhotonNetwork.room.SetCustomProperties(new ExitGames.Client.Photon.Hashtable() { { "Start", true } });
    }
  • RandomMan
    Options
    Okay I found solution. Thanks to Christian_Simon!

    Solutuion is
    void OnPhotonCustomRoomPropertiesChanged()
    {
    var Bool = PhotonNetwork.room.CustomProperties["Start"];
    if (Bool.Equals(true))
    {
    PhotonNetwork.LoadLevel(2);
    }
    }

    public void StartGame()
    {
    PhotonNetwork.room.SetCustomProperties(new Hashtable() { { "Start", true } });
    }