Is there a way to add TrueTypeFont text into an environment?
I want to add names, to objects in the scene, that the user can see, there may be a few hundred objects, so I want to be able to disable them beyond a certain distance using a script.
I’d like it to be a fixed size on screen, but render to texture seems like it could be a pain to manage for, potentially, so many objects.
also I want the text to clip to the viewport, and possibly clip to the depth buffer, so GUI.Label might not be ideal either.
Any hints?
I used GUI.Label, centre aligned.
void OnGUI()
{
if(shownames==false) return;
//if we have names for this object
if(Names.Count>0)
{
//get gameobject.pos+offset_up position in viewport space
Vector3 pos = Camera.main.WorldToViewportPoint (transform.position + new Vector3(0.0f,1.2f,0.0f));
//check we're in camera and within 25 units infront of camera (could raycast this to eliminate occluded objects)
if((pos.x>0.0f)(pos.y>0.0f)(pos.x<1.0f)(pos.y<1.0f)(pos.z>0.0f)(pos.z<25.0f))
{
// show the names!
//get gameobject.pos+offset_up position in screen space
pos = Camera.main.WorldToScreenPoint (transform.position + new Vector3(0.0f,1.2f,0.0f));
//convert Screen_space to GUI_space
pos.y = Screen.height-pos.y;
//create one long string of names with return chars ('/n')
string s = locations[0].getName();
int i=1;
while(i<locations.Count)
{
s += "\n"+locations[i].getName();
i++;
}
// draw GUI Label
GUI.Label(new Rect(pos.x-75, pos.y-(12+20*locations.Count), 150,12+20*locations.Count), s, GUI.skin.GetStyle("label"));
}
}
}