Get user entered name and display to all clients
Hello everyone,
I am having trouble with PhotonNetwork.Instantiate.
Here's the process:
I have a form/menu that the user enters his name/nickname , and after 2 or more players join a room, a player is able
to tap the other player and the tapped player name (not prefab name) will be displayed on screen and to all players.
so far .. , I create the player , where playerName is the name entered by the user .
and what is happening is that the client/user who created the game displays its own name (sine its 3rd person and player can tap on itslef)
and doesn't get the other player's name.
Any hints? or if a totally different approach ?
The purpose is simple, a user will search for the hiding players, when he sees a character, he will tap and every player will read a message like
"John has been caught" according to the user name the player enters..
Thank in Advance
I am having trouble with PhotonNetwork.Instantiate.
Here's the process:
I have a form/menu that the user enters his name/nickname , and after 2 or more players join a room, a player is able
to tap the other player and the tapped player name (not prefab name) will be displayed on screen and to all players.
so far .. , I create the player , where playerName is the name entered by the user .
GameObject tempGO = zombieCharacter; tempGO.GetComponent<NetworkCharacter>().characterName = playerName; monster = PhotonNetwork.Instantiate(tempGO.name , spawnPosition , Quaternion.identity , 0 );
// the hit is a raycast hit
PhotonView pView = hit.collider.gameObject.GetPhotonView();
string name = pView.gameObject.GetComponent<NetworkCharacter>().characterName;
photonView.RPC("PrintMessageOnScreenRPC" , PhotonTargets.All , name + " has been caught");
and what is happening is that the client/user who created the game displays its own name (sine its 3rd person and player can tap on itslef)
and doesn't get the other player's name.
Any hints? or if a totally different approach ?
The purpose is simple, a user will search for the hiding players, when he sees a character, he will tap and every player will read a message like
"John has been caught" according to the user name the player enters..
Thank in Advance
0
Comments
-
Hi,
Probably 'characterName' property is not synchronized across network.
But you do not need it for player name since name is built-in PUN feature. Just set PhotonNetwork.playerName before joining room and use 'playerName' property of player who called "PrintMessageOnScreenRPC".
Also you may find useful setting custom player properties during the game: (player.SetCustomProperties(...) method / player.customProperties pproperty). Properties are synchronized automatically too.0 -
Hello,
Thank you for your time:)
still ..
I couldn't undestand how to access the playerName property of each tapped player.
I tapped a character, and all I have is the hit, which is the player.
How to access the playerName property?0 -
You should use PhotonNetwork.playerName. Set it before you connect or at least before you join a room.
This is the "display name" for a player.
Per PhotonView, you can access another player's name by: somePhotonViewComponent.owner.name.0