So I tried following along to lecture 5 Syncing variables but when I build my app and start the Host/client on the built application and then then run the Unity Editor as the client my displayname still says “Missing name” for both cloned versions of the player in the inspector window. Any help would be appreciated please.
MyNetworkPlayer code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
public class MyNetworkPlayer : NetworkBehaviour
{
[SyncVar]
[SerializeField]
private string displayName = "Missing Name";
[Server]
public void SetDisplayName(string newName)
{
displayName = newName;
}
}
MyNetworkManager code
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Mirror;
public class MyNetworkManager : NetworkManager
{
public override void OnClientConnect(NetworkConnection conn)
{
base.OnClientConnect(conn);
Debug.Log("I connected to a server");
}
public override void OnServerAddPlayer(NetworkConnection conn)
{
base.OnServerAddPlayer(conn);
MyNetworkPlayer player = conn.identity.GetComponent<MyNetworkPlayer>();
player.SetDisplayName($"Player {numPlayers}");
}
}