Search Unity

Third Party Photon, wait till all players join then start the game

Discussion in 'Multiplayer' started by wowcrazyguy, Nov 25, 2019.

  1. wowcrazyguy

    wowcrazyguy

    Joined:
    Sep 24, 2018
    Posts:
    49
    Does anyone familiar with Unity Photon. I try to wait till all players join then start the game. I think PhotonPlayer function is no longer working.

    Code (CSharp):
    1. void OnPhotonPlayerConnected(PhotonPlayer newPlayer){
    2.  
    3.      if (PhotonNetwork.playerList.Length == 2) {
    4.           PhotonNetwork.LoadLevel ("StandardTrack");
    5.       }
    6.       else if (PhotonNetwork.playerList.Length == 1) {
    7.           Debug.Log ("Not Enough PLayers");
    8.           popup.SetActive (true);
    9.       }
    10.   }
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Add a Debug.Log() and write some useful info to the console. Like the player list / length.
    And let us know what happens / doesn't.

    If your room has a maxplayer that's 0 (no limit) or more than 2, your method may fail, when 3 players get in.
     
  3. wowcrazyguy

    wowcrazyguy

    Joined:
    Sep 24, 2018
    Posts:
    49
    Sorry what I mean is I saw this codes from a post in 2015. I try to copy it to my script. I then find out that I cannot type (PhotonPlayer newPlayer) PhotonPlayer won't turn into blue. What am I missing here.

    https://answers.unity.com/questions/1013437/start-game-once-2-players-join-photon.html

    I think this code to make a wait-till-ready system is not working anymore. What should be the updated method in 2019.
     
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Assuming you use PUN 2 now, the code should use Player and PhotonNetwork.CurrentRoom.PlayerCount.
     
  5. wowcrazyguy

    wowcrazyguy

    Joined:
    Sep 24, 2018
    Posts:
    49
    Thanks I just realize there is pun and pun2. I managed to get it works with a delay start tutorial I found.
     
    Last edited: Dec 2, 2019