Multyplayer nameplate not working
Hi I'm working on Multiplayer game and I have tow scenes one is offline scene and the other is online scene,
in the offline scene the player entering is name and when is starting a server as a host the name he wrote appear fine
the problem is when other player joying the server they are gating the same name and its display for all the players
I'm using a singleton script that get the value that the player entering and because its a public static value it display in the other scene, I'm thinking that because I'm using a singleton when new player is logged in is singleton with is new value getting delete
I cant find solution to that
my singleton Code:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI;
public class NameTagManager : MonoBehaviour { public static NameTagManager instance; public static string UserName;
void Awake()
{
if (instance != null)
{
Destroy(gameObject);
return;
}
instance = this;
DontDestroyOnLoad(this);
}
public GameObject inputField;
public void EnterYourUserName()
{
UserName = inputField.GetComponent<Text>().text;
}
}
my Nameplate Display Code:
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Networking;
public class display : NetworkBehaviour {
public Text DisplayName;
public Text DisplayMoney;
[SyncVar]
public string NamePlate;
void Start()
{
CmdNamePlate();
}
private void FixedUpdate()
{
DisplayName.text = NamePlate;
DisplayMoney.text = FindObjectOfType<GameManager>().Money.ToString();
}
[Command]
void CmdNamePlate()
{
NamePlate = NameTagManager.UserName;
}
}
Your answer
![](https://koobas.hobune.stream/wayback/20220613020003im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Match making in Photon 0 Answers
how to implement multiplayer in Unity 2020.3.15f1 0 Answers
Multiplayer and microphone audio streaming 1 Answer
How I can make a Lan multiplayer ? 1 Answer