I am making a multiplayer game with Mirror and trying to make player names that float above players. The client and host can both enter their names but the client's name will just be the host's name. I do not want this. Here's the Name Manager code which is on a prefab.
public class PlayerNameInput : NetworkBehaviour
{
[Header("UI")]
[SerializeField] private InputField nameInputField = null;
public static string DisplayName { get; private set; }
private const string PlayerPrefsNameKey = "PlayerName";
private void Start() => SetUpInputField();
private void SetUpInputField()
{
if (!PlayerPrefs.HasKey(PlayerPrefsNameKey)) { return; }
string defaultName = PlayerPrefs.GetString(PlayerPrefsNameKey);
nameInputField.text = defaultName;
}
public void SavePlayerName()
{
DisplayName = nameInputField.text;
PlayerPrefs.SetString(PlayerPrefsNameKey, DisplayName);
}
}
And this is the Player code which is on the player.
public class WheelController : NetworkBehaviour {
public bool CanMove;
public TextMesh NameMesh;
[SyncVar(hook = nameof(OnNameChanged))]
string PlayerName;
void OnNameChanged(string _Old, string _New)
{
NameMesh.text = PlayerName;
}
[Command]
public void CmdSetupPlayer(string _name)
{
PlayerName = PlayerNameInput.DisplayName;
Debug.Log("fligu fligu da dee eh");
}
public override void OnStartClient()
{
CmdSetupPlayer(PlayerName);
SetDisplayName(PlayerName);
}
}