I would like to use PUN in a single scene. Is this possible?

I would like to use PUN in a singe scene using the Lobby and a specific room or series of rooms. I don't want to load any other scene. I want to have sync'd objects and characters. Is there an example of project with some thing like this?? This is a Unity Project.


Thanks


Herb Rush

Answers

  • Dibbie
    Dibbie ✭✭

    You can have a script inherit from MonoBehaviourPun (requires using Photon.Pun namespace), and then override events like OnConnectedToMaster, OnJoinedLobby, OnCreatedRoom, OnPlayerJoinedRoom, OnPlayerLeftRoom, etc, then you can use the "Getting Started" guide to handle the basic part of connecting and joining: https://doc.photonengine.com/en-us/pun/current/demos-and-tutorials/pun-basics-tutorial/lobby


    Typically, you would join a lobby after connecting to the master server, then however you want to handle creating and joining rooms (ie: joining a specific room, or joining random rooms) is up to you, you could automatically have players join/create rooms after they join the lobby, or setup UI and have a button that does this - when you are ready for gameplay and you have all your players in a room, instead of syncing and loading scenes, you could just send a RaiseEvent or room property to let the master client know to "start the game", however that applies to your game (ie: spawn players at a certain position, set their health, unlock powerups, etc)

  • Thanks.

    1) " instead of syncing and loading scenes, you could just send a RaiseEvent or room property to let the master client know to "start the game"". This is the part that I needed.

    2) "however that applies to your game (ie: spawn players at a certain position, set their health, unlock powerups, etc)". Could you expand on this point? That "however" seems to be cautioning about something.

    I will give it a try.


    Herb Rush


  • " instead of syncing and loading scenes, you could just send a RaiseEvent"

    So Instead of doing this code. I Send a Raise Event to start the Game.

    private void StartGame() {

        if(PhotonNetwork.IsMasterClient == true) {

          if (debug == true) Debug.Log("QuickStartRoomController: Starting Game in Room Controller with Scene Index = " + multiplayersSceneIndex);

          // Start the game by loading the Scene of the game.

          PhotonNetwork.LoadLevel(multiplayersSceneIndex);

        }

      }


    Thanks


    Herb Rush

  • if (PhotonNetwork.IsMasterClient == true)

        {

          object[] datas = new object[] { 0.1f, 0.2f, 0.3f };

          PhotonNetwork.RaiseEvent(START_GAME, datas, RaiseEventOptions.Default, ExitGames.Client.Photon.SendOptions.SendReliable);

        }

    Something like this?

    Herb

  • Dibbie
    Dibbie ✭✭


    Yup, something like that could work, assuming the numbers in your object array are going to be handled by a OnEvent to receive that "START_GAME" (https://doc.photonengine.com/en-us/pun/current/gameplay/rpcsandraiseevent#ioneventcallback_callback - note the OnEnable / OnDisable setup for OnEvent)

  • It seems to work with a bit of book keeping but I am not using IF(PHONTON.NETWORK.ISMASTERCLIENT == TRUE). I do Raise Event for all and then go to gamesetup creating the avatar,....

    Any Suggestions would be helpful here.

    Herb Rush