- Home /
Question by
ZuhairGhias · Apr 27, 2018 at 06:21 AM ·
networkingnetworkmanager
What is a good way to keep score in a multiplayer lobby?
I am trying to setup a multiplayer game where during a session, the scene changes but throughout the scenes players maintain their scores. What is a good way to go about it. I am leaning towards an approach like the one below, but is this a good way to go about it?
public class Manager : NetworkManager {
public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId)
{
if (networkSceneName == "Lobby" && !sessionStarted) {
// The original NetworkManager code
var player = (GameObject)GameObject.Instantiate(/*args*/);
NetworkServer.AddPlayerForConnection(/*args*/);
// Add players to a list by value
Player connectedPlayer = new Player(player.GetComponent<NetworkIdentity>().netId.Value);
lobbyPlayers.Add(connectedPlayer);
print("Player " + connectedPlayer.id + " Spawned");
}
}
I basically try and maintain a list of players by their IDs. I haven't fully tested this yet but just wanted to check for suggestions before working on this any further.
Comment