- Home /
Question by
Slences · Aug 26, 2015 at 12:30 PM ·
networkingstringsynchronization
Sync player name (Networking)
I'm using the new networking system and I can't really figure out how to display each player's name for all clients. The problem is that each client does not see the other clients name. I'm using these methods:
public string playerName;
public override void OnStartLocalPlayer()
{
playerName = PlayerPrefs.GetString("PlayerName");
// Give the server my name
CmdProvideName(playerName);
}
[Command]
void CmdProvideName(string name)
{
playerName = name;
// Broadcast to all clients
RpcPlayerName(name);
}
[ClientRpc]
void RpcPlayerName(string name)
{
playerNameUI.GetComponent<Text>().text = name;
}
void Update()
{
// Keep the name updated for incoming connections
RpcPlayerName(playerName);
}
What's a good way to approach this? Thanks in advance!
Comment
Why not make the name a SyncVar? with a hook function to set it in the UI
I tried to make it a syncvar but then I'm still not sure how to do it.
Best Answer
Answer by seanr · Aug 26, 2015 at 08:01 PM
like the way color is synced here:
http://forum.unity3d.com/threads/synchronizing-colors.334944/#post-2168080