[PUN] A few questions regarding basic Multiplayer Functions

I have two Scenes, Menu and TestMap. On Menu you’re able to create a server and join one, the first issue I’m having is with listing players. I’ve tried various things but the only way I can get Unity to add the PhotonNetwork.playerName to a Text object and add a new line without it constantly looping is either through a one off IEnumerator or by adding a bool which once disabled stops the loop. Only issue is this also makes it a run once thing. So instead I used the first and set it inside the OnPhotonPlayerConnected.

IEnumerator UpdatePlayerList(PhotonPlayer o, string func) {
        yield return new WaitForSeconds (0.1f);
        if (func == "Add") {
            if (o.GetTeam ().ToString () == "blue")
                BlueTeam.GetComponent<Text> ().text += o.name + "\n";
            if (o.GetTeam ().ToString () == "red")
                RedTeam.GetComponent<Text> ().text += o.name + "\n";
        }

        if (func == "Remove") {

        }

        Debug.Log (o.name);
        Debug.Log(o.GetTeam().ToString());
    }

The next issue I’m having is I have a Canvas for the lobby, when players are meant to be in the Lobby this canvas is activated but I’m trying to get the game to allow the Master Client to start the initial game but there after any new connecting players I’d like to be able to either load the TestMap scene on their own or be loaded in straight away. I’ve set a button to use PhotonNetwork.LoadLevel which works but I’m seeing the other players in the Menu scene.

The approach to use the on join callback should be fine for your case. You should recreate the whole canvas hierarchy for the names. That way you can also call the method when someone leaves.

Load level requires you to also set automaticallySyncScene to true. Otherwise the others won’t follow.
Hope that helps.

I figured out the SyncScene shortly after enabling it lol, I managed to accomplish what I had in mind by using an RPC that adds the players name to everyones UIText, I just haven’t implemented a way to remove them yet.

1 Like