- Home /
Player names all displayed as local player
Hello, i am currently working on a simple unity/photon powered multiplayer game. I have set a script to display player names above the heads of all connected players. The script is as follows:
using UnityEngine;
using System.Collections;
public class PlayerName : MonoBehaviour {
void OnGUI()
{
Vector3 offset = new Vector3(0, 3, 0); // height above the target position
Vector3 point = Camera.main.WorldToScreenPoint(transform.position + offset);
point.y = Screen.height - point.y;
GUI.Label(new Rect(point.x - 35, point.y - 20, 200, 20), PhotonNetwork.playerName);
}
}
This script is attacked to the instanced player object which has a photonview attached. The script will display names above all connected users, however the name will be that of player belonging to the local client. i.e. if you connect with the player name "guest123", all players will display "guest123" above their heads. Here is a image to illustrate the issue.
Answer by tobiass · Sep 12, 2012 at 02:16 PM
PhotonNetwork.playerName is the name of your local player only. Your avatars will already have a PhotonView component attached to them. Per avatar, get this component and display: photonView.owner.name.
Lol, thanks a lot Tobiass, I have tried so many work-arounds yet something so simple fixed the issue :P
I know this is old but can you post your code for this I've been trying for hours and can't figure out how to get this to work! Thanks.
Please post the code, or tell us how to set the photonView.owner.name / photonView.name!
SET a user's name with PhotonNetwork.playerName. This is being synchronized across all players in a game. There is a list of players in the room you're in: PhotonNetwork.playerList. Per player in that list you can access the name.
ACCESS any PhotonView owner's name via: pv.owner.name
The PhotonView.name is inherited from $$anonymous$$onobehaviour: http://docs.unity3d.com/Documentation/ScriptReference/$$anonymous$$onoBehaviour.html
I was using PhotonNetwork.player.name ins$$anonymous$$d of PhotonNetwork.playerName. Wasted an hour to find this ;)
Your answer
Follow this Question
Related Questions
How to instatiate two players simultaneoulsy before loading level 1 Answer
Photon Networking Spawn player 2 0 Answers
Switching weapons in PhotonNetwork 1 Answer
Photon Network instantiate problem when Master changes 0 Answers
When using photon sometimes it fails to find local game object. 0 Answers