- Home /
Draw 2d text in a 3d space?
How do i (using javascript) draw a piece of 2d text at any given position on screen and mak e it face the camera? basically a billboard with a string as it's texture. :)
Answer by Benjames · Oct 19, 2013 at 05:04 PM
So I deleted all my original post because I wanted to simplify the answer to this in case anyone came looking here.
void OnGUI()
{
GUI.enabled=true;
Camera cam=Camera.current;
Vector3 pos=cam.WorldToScreenPoint(new Vector3(0,5,0));
GUI.Label(new Rect(pos.x,Screen.height-pos.y,150,130),"Hello");
}
Here are some links that should explain things..
(Note) The screen y coordinates are opposite to the camera coordinates. O yah this is C# sorry.
Answer by fafase · Aug 22, 2012 at 05:16 PM
You can use 3DText but it shows from anywhere you are in the scene through any object.
You could have a plane and you put your text as a texture and use:
var target:Transform;
function Start(){
target =GameObject.Find("Player").trasnform;
}
function Update(){
transform.LookAt(target);
}
3DText sounds good, i'm using it as an effect to show how much damage you've hit, you'll have to have line of sight most of the time anyway :) The problem with a texture is i can't change the numbers XD
EDIT: http://docs.unity3d.com/Documentation/ScriptReference/Text$$anonymous$$esh.html found this :)
You can change the shader used for 3D text if you don't want it to show through everything.
Oh oh.Are you simply trying to create a GUI? Unity has a full class for that. Actually, a text displayed on the screen always facing the camera is a GUI: http://docs.unity3d.com/Documentation/ScriptReference/GUI.Label.html
Your answer
![](https://koobas.hobune.stream/wayback/20220613080027im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Particles are rendered in front of tree billboards 1 Answer
DrawMesh always drawn before gameobjects 1 Answer
create line on a texture 2 Answers
Debug.draw rect 2 Answers