- Home /
Setting player names on network
Hi all,
I'm trying to assign individual usernames to players in a network game. I have overwritten the network manager and created a custom network manager GUI where every user can enter a name before either starting or joining a server. The username is assigned to a variable on the network manager and every player gets his name from the network manager in the Awake function and assigns it to a SyncVar variable on the player controller but this approach seems to be not working as remote players seem to have the same name as the server client.
void Awake()
{
var name = GameObject.FindObjectOfType<CustomNetworkManager>().username;
CmdAssignName(name);
}
[Command]
public void CmdAssignName(string name)
{
username = name;
}
Is there a better way to accomplish something like this?
Regards, Damir
It looks like the wrong username comes from the input field. On both the host and client the server host username is assigned.
public class CustomNetwork$$anonymous$$anager : Network$$anonymous$$anager {
public string username;
public void StartupHost()
{
SetPort();
username = GetTextFromInputField(main$$anonymous$$enu, "InputFieldUsername");
Network$$anonymous$$anager.singleton.StartHost();
}
public void JoinGame()
{
SetIpAddress();
SetPort();
username = GetTextFromInputField(main$$anonymous$$enu, "InputFieldUsername");
Network$$anonymous$$anager.singleton.StartClient();
}
}
Still can't figure out why this is happening, I was expecting every client would be using his own text field.
Your answer
