I’m currently creating a scoreboard for my multiplayer game. But first I need to list all players in an array. How can I insert each player into an array? On each device it only shows one player. For example, player1
is in pc[0]
and player2
is in pc[1]
.
NetworkManager networkManager = NetworkManager.singleton;
pc = networkManager.client.connection.playerControllers;
for (i = 0; i < pc.Count; i++)
{
if (pc[i].IsValid)
showname.GetComponent<Text>().text = pc[0].gameObject.name;
showscore.GetComponent<Text>().text = pc[0].gameObject.GetComponent<multscore>().score.ToString();
showname2.GetComponent<Text>().text = pc[1].gameObject.name;
showscore2.GetComponent<Text>().text = pc[1].gameObject.GetComponent<multscore>().score.ToString();
}
if
statement. Is that intentional? Without that, the condition will only apply to the subsequent line, while the other remaining lines will be executed for every ’pc[]`, even if it’s invalid. I imagine that might cause problems here.if (!pc[i].IsValid) break;
Then you wouldn't want to use fixed indices0
and1
but rather usei
.. therefoe I would also store all the text references in arrays so you can map each player to its text usingi