I’m making a list that keeps track of the players names and scores in a tournament type of game. Each players name is updated with an RPC (multiplayer) at the start of each match like so:
[PunRPC]
void EditPlayerListWithName(PhotonPlayer nPlayer, string pName)
{
for (int i = 0; i < PlayerList.Count; i++)
{
if(PlayerList[i].photonPlayer == nPlayer)
{
PlayerList[i].playerName = pName;
}
}
}
But this creates duplicate “playerName” (which is a public string) in my “PlayerList”. How can I scan the list for playerName duplicates and remove the duplicate?
Why are you using strings and not player ID?
Just use a player ID that doubles as an index to some array that keeps player relevant information like name, team, score, etc.
public struct PlayerData {
public string name;
public int team;
public int score;
public etc whatever;
}
hold an array of something like that where ever you “manage” the game, I always have a main class that handles game logic and everything goes though it.
when you start the game give each player an integer ID and make the ID the same as the array index.
public class GameManager {
PlayerData[] players;
public PlayerData GetPlayer(int id){
return players[id];
}
}
maybe you can tell us what you don’t understand about the concept i suggested/where you’re struggling with implementing it