How to set my text to real object

I want to set my text in GUI layer to a position of an object but can’t do that work with some thing like this code because my screen size maybe change and this code hang when screen size is change but my X variable is always in true place and my main problem is Y

var TextStyle = new GUIStyle();
		TextStyle.font = font;
		TextStyle.normal.textColor = Color.white;
		var position = Camera.main.WorldToScreenPoint(timer.transform.position);
        GUI.Label(new Rect( position.x,Screen.currentResolution.height - position.y - 450, 100, 20), "123" , TextStyle);

I want to put my text in this place :


If you want it in a constant world position and not screen position, why not use 3d text instead of GUI text?


Don’t worry about your game being 2d. I always use 3d text for 2d games, as long as it’s facing the camera it will appear 2d for you, and if your game is 2d then I don’t expect the camera to rotate around it…

1 - Create a 3d text object, select the font and color from the inspector (or code if you prefer).

2 - Set the scale of the 3d text object to 0.1,0.1,0.1 so that it appears more crisp.

3 - Change the font size parameter of the object if you want to make the writing bigger. It will remain sharp.

4 - To change the text from code, create a reference to it in your script as TextMesh (set the reference in the inspector), then set the text property to whatever you want it to display. See example below.

5 - If you don’t want to set the TextMesh in the inspector, you can use GameObject.Find() to find the object by name, and then use GetComponent to get the TextMesh component of the object.

var textMesh : TextMesh;

function Start() {
    textMesh.text = "123";

Try this: