- Home /
Multiplayer adding player names and health above each player
I'm making a 3rd person navy game where all the players are ships. In the networked version I want to make sure that each player's name show above their ship. I would prefer using GUIText so the text stays the same size no matter the range. Is there a good example out there, or can some one give me show me a little code to give me the general idea of how to do this?
Thanks.
Answer by Eric5h5 · Jun 21, 2010 at 08:18 PM
Use this script on the wiki.
http://wiki.unity3d.com/index.php?title=ObjectLabel
here is the real link
Answer by AnaRhisT · Jun 21, 2010 at 08:09 PM
Create a 3D Text and write something in the text, now correct it to the ship's head or whatever, remove the text, add to it a networkView
and another script from Leepo's tutorial called NetworkRigidbody or something, make sure the obseved slot is networkRigidbody script and not something else, use PlayerPrefs
function to save the name they wrote in the beginning - shown in Leepo's tutorial. Leepo's networking tutorial : http://forum.unity3d.com/viewtopic.php?t=30788
Answer by terjesorheim · Dec 11, 2012 at 02:08 PM
Try this:
private var localName:String; // Holds the local player name
private var namePlatePos : Vector3;
var namePlate:GUIStyle;
function OnGUI() {
// Place the name plate where the gameObject (player prefab) is
namePlatePos = Camera.main.WorldToScreenPoint(gameObject.transform.position);
GUI.Label(Rect((namePlatePos.x-50), (Screen.height - namePlatePos.y+10), 100, 50), localName, namePlate);
}
Answer by Tetrad · Jun 21, 2010 at 08:07 PM
This is going to be the key to your implementation: http://unity3d.com/support/documentation/ScriptReference/Camera.WorldToScreenPoint.html
Basically have a GUIText object point to a transform, and every frame set its position using that function. I think GUIText objects use normalized screen space (so 0-1 instead of 0-Screen.width/height), but that should just be a simple division by Screen.width/height to get the coordinates to be correct.
Answer by mlkielb 1 · Jun 21, 2010 at 08:32 PM
Awesome, thanks for all the quick responses, I will check out all the links and see what works best.
Just letting you know, this isn't like a forum. You should make a comment on one of the answers. Good luck!
Your answer
Follow this Question
Related Questions
Multiplayer Chat Script (Problem : mixed names) 1 Answer
A name For the Character Please Help 3 Answers
Network object references to each other 1 Answer
Displaying players name above in multiplayer 1 Answer
Send last standing player name 2 Answers