- Home /
The question is answered, right answer was accepted
Unity Photon Name-Tag Problem
So for the last week I have been trying to figure out a name tag system for a photon multiplayer game. I am able to transfer the users input from scene to scene, and put it above the player's head. My issue now is having it synced for other users. I don't fully know how to explain this so let me show you some pictures.
Here is the code I have so far.
Here is choosing your name and the outcome of two clients connected to the server. http://imgur.com/a/QwRyZ
Answer by Zessfarr · Jul 07, 2017 at 05:31 AM
Alright so I figured it out! Thanks to ChristianSimon, and one of my friends. First off I didn't have Photon updated in unity which made some things obsolete I think.
I only needed to use two scripts for it to work instead of three. Here is a picture: http://imgur.com/a/cMR44
The first script is the PlayerNamePlate script. It obtained the users input and carried it over to the lobby scene where people can play.
The Second script did all the magic. On the start method I set the PhotonNetwork.player.NickName to be equal to the users Input. Next, In the update function I set the players Name-Tag to be equal the PhotonView.owner.Nickname.
From there it updates the player names correctly, hopefully I explained everything well. If I did not let me know and ill see if I can do a better job.
Answer by ChristianSimon · Jul 06, 2017 at 08:08 AM
Hi,
it should be enough to just update PhotonNetwork.player.NickName on the local client. The updated name is then automatically synchronized across all clients. If you now want to change the displayed name of the component, you have different ways to achieve this:
1) Set the text of the text component (or similar) in the Update() function or any other function, which is executed regularly (not recommend because this might have a bad influence on performance).
2) Use OnPhotonPlayerPropertiesChanged callback which is also called when the NickName gets updated. You can read about this callback here.
3) Use a separate RPC (or RaiseEvent) call to inform other clients to update the name displayed by the text component.
Alright sweet! When I have time today ill try this out thanks!
Follow this Question
Related Questions
How to add Turn Based to Photon Pun 1 Answer
How to check distance between two players (photon multiplayer) 2 Answers
How to change colors in unity using photon? 0 Answers
How to connect to our own dedicated server using photon networking in unity?(Self-hosted) 0 Answers
Photon Cloud, Multiplayer Damage script 0 Answers