Search Unity

How to instatiate two players simultaneoulsy before loading level

Discussion in 'Multiplayer' started by pawan-arora, May 2, 2014.

  1. pawan-arora

    pawan-arora

    Joined:
    Oct 29, 2013
    Posts:
    1
    Hi, I'm new in unity networking and I'm using photon server for multiplayer game, and I've two scenes.

    In first scene, I want a new player who has joined the room, to wait for another player to join. After total player count equals two I'm loading a new scene, where I'm actually instantiating prefab. But only the last player who has joined the room, actually able to enter in new scene, other player stuck in first scene.

    The code in first scene:

    Code (csharp):
    1.  
    2. void OnJoinedRoom()
    3. {
    4.     if (PhotonNetwork.countOfPlayers == 2)
    5.     {
    6.     PhotonNetwork.LoadLevel(1);
    7.     }
    8. }
    Code in second scene:
    Code (csharp):
    1.  
    2. void start()
    3. {
    4.   PhotonNetwork.Instantiate("PlayerPad", Vector3.zero, Quaternion.identity, 0)
    5.  
    6. }
    Does anyone know how can I make possible to enter two more player simultaneouly in new scence, after meeting some condition first. Thanks in advance.
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    PhotonNetwork.countOfPlayers is not the count of players in "this" room. It's the count of players online in your game in general.
    You might want to implement OnPhotonPlayerConnected(PhotonPlayer newPlayer){ ... }.

    If you setup MaxPlayers to 2, you can be sure that the player count is 2 when this gets called but you can also check: PhotonNetwork.playerList.Length == 2 or PhotonNetwork.otherPlayers.Length == 1.