I have used the examples in the networking samples and built a simple project where others are joining. Apart from the prefab of my character I also added in the prefab a 3d text to appear above my chars head like so many games do. However until now I either have the name appear for my char by I don’t see it above the other players heads either all the client avatars are having the same name as me. So how I make the names appear correctly? What am I not sending through the code from the networking example, because stream serialize doesn’t support string. Any help would be much appreciated.
you can convert the string into a format supported by the stream → you write it as series of byte
So its only a matter of passing the text through the NetworkInterpolatedTransform.cs script then? Too simple hmmm…
A simple RPC that is run in the setup function (like the onnetwork create or alike) would work as well.
i would not push it through something that is meant to run regularily
I did use an rpc into the setup script attached onto the 3d text object which was setting the textmesh to the name of the avatar but I was getting the same name appearing for everyone e.g. I had the name Antonios and I saw the name Antonios above all the chars.
Sounds like you likely don’t send the RPC to all other clients then or that you call the RPC BEFORE you actually set the name.
Alternatively you didn’t cache the call or when you don’t intend to do that, you forgot to react in your new player connected script on the client accordingly by sending out the rpc.
The name thats streamed by default is the name that you set in the editor
That depends on your setup and how you handle it.
I assume you worked with different machines right?
the alternative approach is another serialization pipe which handles stuff like name and other general setup for example. set the transfer there to delta compressed and you are all fine as it will only send the data once and thats it.
Yes worked on different machines. Will give a try once more or go with the serialization. Thanks for the tips and the help.
Hi Antonios. I took this script directly from my game, I hope it will help. You can probably modify it so that it will work for you. Just like you, I added a TextMesh above my characters, then I added this script to my CharacterController. I haven’t really taken the time to explain the script, but I’m sure you can figure it out. Good luck.
var nameText : TextMesh;
private var playerName : String;
private var playerOldName = "";
private var nameTime = 0.0;
private var team : String;
private var nametextTeam : String;
private var camTeam : String;
function Start()
{
var raceSelectionObject = GameObject.Find("Race_Selection_Data");
var raceSelectionData = raceSelectionObject.GetComponent(Selection_Info);
playerName = raceSelectionData.SendPlayerName();
team = raceSelectionData.SendSide();
nameTime =Time.time +1.0;
}
function Update()
{
var cam = GameObject.Find("Camera");
playerName = GetComponent(Player_Stats).playerName;
if (playerName != playerOldName Time.time > nameTime playerName != null)
{
networkView.RPC("DisplayPlayerName", RPCMode.All, playerName);
playerOldName = playerName;
nameTime = Time.time + 1.0;
}
if (nameText != null)
{
if ((networkView.isMine || gameObject.tag != cam.tag) nameText != null)
{
nameText.renderer.enabled = false;
}
else
{
nameText.transform.LookAt(cam.transform);
}
}
}
@RPC
function DisplayPlayerName(playerName : String)
{
nameText.text = playerName;
}
Thank you for the help and the code. Much appreciated.