NPC Name Over Head

What are the recommended ways of putting the NPC’s name over their head?

I tried a GUI.Label but that doesn’t work as the Text over the head should scale with distance, ie, the further away you are, the smaller the text should be.

I have searched the forums and haven’t found a good a way to do this. Do I have to change fonts based on the distance from the camera?

Thanks

Check out the code provided by AaronC in another thread:

This code uses a GUIText.

I tried downloading that project but it says it is an invalid zip file.

Yeah, I had that problem too. I used the InfoZip utilities to unzip it.

You might also be able to use a TextMesh to display the names. TextMeshes are objects in 3D space, so they can be placed above the character and will scale as appropriate.

Thanks!

Used a TextMesh ( 3D Text ) to show NPC names.

How do you lock the text mesh to always face the player?

using UnityEngine;
using System.Collections;

public class NPCName : MonoBehaviour
{
Transform nameText = null;

// Use this for initialization
void Start()
{
this.nameText = transform.Find(“NameText”);
}

// Update is called once per frame
void Update()
{
if (this.nameText != null)
this.nameText.forward = Camera.mainCamera.transform.forward;
}
}

I tried just doing a Transform.LookAt(camera), but the text was always backwards. Seems like to me the forward of the 3d text is backwards.

I got it to work with my hack. Anyone have the right way to do it?

Check out this thread for a code snippet to make transform.LookAt look in the opposite direction.

If your not doing to much stuff with it and you want to use the LookAt script, I’d suggest scaling the text mesh in negative X and Z. Had the same problem myself but this fixed it right away, and the selecting of the mesh wasn’t affected either.

yes,It works fine.

Heya,

To the windows users who had trouble downloading the zip, my apologies. I just reloaded the file- I dont know if its any good but if anyone feels like checking that would be great. Its about 3mb

http://deepwater3d.com/DW3D/Realtime/MG_Advanced.zip

Thanks
AaronC

on unity it says to insert a semicolon at line1, line2, line6

and its says that : is an unexpected character

.

Why?

I use this, if you want you can’t remove the “public” from Camera.
:slight_smile:

using UnityEngine;
using System.Collections;

public class NombrePersonaje : MonoBehaviour {

public string Nombre;
public Camera cam;
TextMesh texto;

// Use this for initialization
void Start () {
cam = Camera.main;
texto = GameObject.Find("Nombre_Char").GetComponent<TextMesh>();
texto.text = "<"+Nombre+">";
}

// Update is called once per frame
void Update () {
if (cam != null) {
transform.LookAt (cam.transform);
}else
{
cam = Camera.main;
}
}
}