- Home /
 
 
               Question by 
               kratosrg · Jan 04, 2014 at 06:37 AM · 
                networkingplayerphotononline  
              
 
              Player names all displayed as local player photon
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 "player1", all players will display "player1" above their heads. Here is a image to illustrate the issue.
 
                 
                aaa.jpg 
                (170.5 kB) 
               
 
              
               Comment
              
 
               
              Answer by MrCode · Jan 12, 2014 at 02:02 PM
     GUI.Label(new Rect(point.x - 35, point.y - 20, 200, 20), GetComponent<PhotonView> ().owner.name;
 
               :)
Answer by InfernoZYB · Mar 02, 2015 at 06:49 AM
this is what i did for mine and it works. (Yea i know about a year later...)
public TextMesh text;
 // Use this for initialization
 void Start () {
     text.text = photonView.owner.name;
 }
 
 // Update is called once per frame
 void Update () {
 
 }
 
               }
Your answer