- Home /
Displaying players name above in multiplayer
Hi!
In my game, every player has a child GameObject called "NameAbove" which contains GUIText component. Here's my code:
//class Player
void Update()
{
//if(networkView.IsMine)
if (dataSet && !nameSet)
{
SetNameAbove(this.characterName); // i've tried also RPC - no result
}
}
[RPC]
void SetNameAbove(string n)
{
gameObject.transform.FindChild("NameAbove").GetComponent<GUIText>().text = n;
nameSet = true;
}
So i need every player to display his own name having set it to his child GO in GUIText component.
Thanx in advance.
Could you explain a little bit more what your problem really is ?
The text is not visible ? The text doesn't change ? Please, give details, we are not wizards.
That's how i get player nickName;
void Update() {
if (networkView.is$$anonymous$$ine) // here we recieve $$anonymous$$Y player name
{
if (!dataSet && myPlayerdata.Length > 0)
{
networkView.RPC("AdjustPlayerDataOnEnterWorld", RPC$$anonymous$$ode.All, this.networkView.viewID);
}
}
}
[RPC]
public void AdjustPlayerDataOnEnterWorld(NetworkViewID id)
{
NetworkView view = NetworkView.Find(id);
view.GetComponent<Player>().characterName = myPlayerdata[0];
networkView.RPC("AdjustPlayerName", RPC$$anonymous$$ode.AllBuffered);
networkView.RPC("SetNameAbove", RPC$$anonymous$$ode.AllBuffered);
view.GetComponent<Player>().level = int.Parse(myPlayerdata[1]);
view.GetComponent<Player>().raceID = byte.Parse(myPlayerdata[2]);
...
dataSet = true;
}
There is every player recieve his own data including name. I want every player to show his own nickname in his child GameObject in his GUIText over network yet no one sees other's names or everyone sees $$anonymous$$Y name above all players.
Where does myPlayerData come from? The problem might be in line 15
view.GetComponent<Player>().characterName = myPlayerdata[0];
It's possible that each client is trying to set its own name to everyone else's character.
no, i've tested this question and have found out that each client recieves his own data... it's 100%...
Hmm... Why do you call an "AdjustPlayerName" and "SetNameAbove" RPC within your AdjustPlayerDataOnEnterWorld RPC? Once you've gotten the player's name correctly for every player, it seems like it'd be a simple matter of creating a gui child over the player with the name inserted in. No need for more RPCs?
Answer by J.Mad · May 29, 2015 at 08:01 AM
You need a canvas. A player should have a small child canvas set as World Space. Canvas should have an child object with Text. Canvas should have some script that will be facing the canvas to the camera. That is a "modern GUI" approach.