Networked player name tag not in correct position.

Anybody have any experience with unity networking and can help me out with this? I am just trying to get player name tags to be over other players. Here is my OnGUI code on the players PlayerNetworkController:

	void OnGUI(){
		if(!networkView.isMine){
			Vector3 labelPos = thisCamera.WorldToViewportPoint(transform.position + new Vector3(0, 1, 0));
			
			GUI.color = Color.black;
			GUI.Label(new Rect(labelPos.x, labelPos.y, 200, 200), "Name");
		}
	}

It should be above the player. Instead, it’s on the top left of the screen.

I think you should use WorldToScreenPoint instead. Looking at the WorldToViewportPoint reference you see that its values are between 0,1.

WorldToScreenPoint instead returns values in range of 0,Screensize.
WorldToScreenPoint reference

printing the labelPos is giving strange results like this:
(0.6, 3141130.0, 0.0)

but mostly it just prints 0, 0, 0.

using thisCamera.WorldToScreenPoint does exactly the same thing. Here is my full script:

public class PlayerNetworkController : MonoBehaviour {
	
	private string playerName;
	
	private Transform worldMesh;
	private Transform viewMesh;
	
	private MouseLook thisMouseLook;
	private Camera thisCamera;
	
	// State synchronization
	private Vector3 newPos;
	private Quaternion newRot;
	
	// Use this for initialization
	void Start () {
		worldMesh = transform.FindChild("playerMesh_w");
		//viewMesh = transform.FindChild("playerMesh_v");
		
		thisMouseLook = GetComponent<MouseLook>();
		thisCamera = transform.FindChild("playerCamera").camera;
		
		if(!networkView.isMine){
			thisMouseLook.enabled = false;
			thisCamera.gameObject.SetActive(false);
		}else{
			worldMesh.gameObject.SetActive(false);
			
			// Get the player name from PlayerPrefs
			playerName = PlayerPrefs.GetString("username");
			
			// Grab the GameManager and tell it to change your name
			GameObject gameManager = GameObject.Find("GameManager");
			gameManager.networkView.RPC("Server_RequestNameChange", RPCMode.Server, Network.player, playerName);
		}

	}
	
	// Update is called once per frame
	void Update () {
		// Lerp the bastard
		if(!networkView.isMine){
			transform.position = Vector3.Lerp(transform.position, newPos, Time.deltaTime * 10);
            transform.rotation = Quaternion.Lerp(transform.rotation, newRot, Time.deltaTime * 10);
		}
	}
	
	void OnSerializeNetworkView(BitStream stream, NetworkMessageInfo info){
		if(stream.isWriting){
			Vector3 oldPos = transform.position;
			Quaternion oldRot = transform.rotation;

			stream.Serialize(ref oldPos);
			stream.Serialize(ref oldRot);
		}else{
			newPos = Vector3.zero;
			newRot = Quaternion.identity;
			
			stream.Serialize(ref newPos);
			stream.Serialize(ref newRot);
		}
	}
	
	void OnGUI(){
		if(!networkView.isMine){
			//Vector3 relativePosition = thisCamera.transform.InverseTransformPoint(transform.position);
    		//relativePosition = new Vector3(relativePosition.x, relativePosition.y, Mathf.Max(relativePosition.z, 1.0f));
			//Vector3 labelPos = thisCamera.WorldToScreenPoint(thisCamera.transform.TransformPoint(relativePosition + new Vector3(0, 1, 0)));
			Vector3 labelPos = thisCamera.WorldToScreenPoint(transform.position + new Vector3(0, 1, 0));
			
			GUI.color = Color.black;
			GUI.Label(new Rect(labelPos.x, labelPos.y, 200, 200), "Name");
			print(labelPos);
		}
	}
}

Oh i see i think you are using the wrong camera. The other player tries to get the correct screen point from his camera not from yours.
That might cause your problem.

Have any idea how I could get the player’s camera? This is where I am pretty confused. Maybe I should do the name tags in a completely different way.

Just make the name an attributte of the player (Like it should be, imo) then run a test to get all buffered players in the area, grab the position, raise the Y value of the original position, then draw the lable. Run this on the players camera and voila, names above players.

Camera.Main

Tried that. For some reason, players can only find their own player object when doing a GameObject.FindAllWithTag(“Player”);

Don’t think I can do this as there will a camera for each player, and there can only be one main camera. Unless Camera.Main doesn’t return the camera if it is disabled.

Is there any way to just to display a nametag over a player that I am looking at? I have all of the raycast stuff down, but I can’t get a networkview owner from another players gameobject so I can’t compare it to find the players name in the database.

I am just really confused. Is there something I am missing here… Is there some sort of way I should be storing the player data? currently whenever a player joins, that players NetworkPlayer and Name are added to a database that all players on the server can see.