Display player Name
Options
I want to differentiate between players by letting them write their name in an Input Field and display the name over their head in the game.
I am using this script as a component of the Input field:
I don't know why the heck it is not synchronizing the Player.ID of the object.
The Name always changes on both players, not only mine.
I would like to send the Name that is mine to other players and they set the received name over my Avatar and I receive their name and can set them over their Avatar.
I would like to use RPC, because the rest of the game is based on RPCs as well.
Thanks for helping
I am using this script as a component of the Input field:
public static string Name; public void Run() { print(PhotonNetwork.player.NickName); Name = gameObject.GetComponent<InputField>().text; PhotonNetwork.player.NickName = Name; print(PhotonNetwork.player.NickName); }And this script as a component of the Avatar with an TextMesh-Object as a child.
public class NameAuslesen : Photon.MonoBehaviour { //private string localName; private string NickName; // Use this for initialization void Start () { } // Update is called once per frame void Update () { photonView.RPC("HeadUpdate", PhotonTargets.All, NickName); if (NameFestlegen.Name != "" && NameFestlegen.Name != NickName) { //gameObject.GetComponent<PhotonView>().ownerId = PhotonNetwork.player.ID; NickName = gameObject.GetComponentInChildren<TextMesh>().text = NameFestlegen.Name; //HeadUpdate(localName); //GetComponentInChildren<TextMesh>().text = PhotonNetwork.playerName; } } [PunRPC] public void HeadUpdate(string Name) { //PhotonView photonView = gameObject.GetComponentInChildren<PhotonView>(); print(Name+ " " + gameObject.GetComponent<PhotonView>().ownerId + " " +PhotonNetwork.player.ID); if (this.photonView.ownerId != PhotonNetwork.player.ID) { //GetComponent<PhotonView>().text; string otherName = gameObject.GetComponentInChildren<TextMesh>().text = NameFestlegen.Name; } } }My problem seems to be the RPC, because the masterClient (first one joining the room) is getting the Name and 0 as gameObject.GetComponent().ownerId (-> the scene is the owner) and 1 for the PhotonNetwork.player.ID; the second player is getting 1 as gameObject.GetComponent().ownerId and 2 for PhotonNetwork.player.ID.
I don't know why the heck it is not synchronizing the Player.ID of the object.
The Name always changes on both players, not only mine.
I would like to send the Name that is mine to other players and they set the received name over my Avatar and I receive their name and can set them over their Avatar.
I would like to use RPC, because the rest of the game is based on RPCs as well.
Thanks for helping
0
Comments
-
I solved it. I just couldn't stick to RPCs.
I used the ShowInfoOfPlayer Script of Photon and adapted it to my Script on the Input Field.
0