TextMesh instead of OnGUI ?

Hi its the JavaNoob again lol :slight_smile:

quick question please ,I am not quite getting the understanding of the textmesh command structure (yes i have read and re read the docs lol) I just need to know how to replace this

function OnGUI(){

GUI.skin = MenuSkin;

GUI.Label (Rect (400,120,400,100), "Checkpoint : " + ckp);
GUI.Label (Rect (340,10,110,100), "Laps : " + lap);

}

With a textmesh instead …

I tried this but to no avail :frowning:

var TextMesh : text;

   GetComponent(TextMesh).text = "Checkpoint: "+(ckp);
     GetComponent(TextMesh).text = "Lap: "+(lap);

Can anyone tell me what im missing please :slight_smile: ? I really have tried on this one I promise :()

The reason I want to use textmesh is because its a 3d object so differing resolutions to be output are not a concern ,or am I completely incorrect on this lol ?

Or more simply is there a way to set a guilabel (or textmesh) position to 50% of a screen width (half way) regarless of resolution ? 1920X1080 and 640X320 would both have the GUIlabel positioned exactly dead centre at the top of the screen ( I realse with Guilabels you would still need to scale them accordingly hence why I would like to use text mesh instead .

using UnityEngine;
using System.Collections;

public class ScaleGUIDemo : MonoBehaviour {
	
	float originalWidth = 1024.0f;  
	float originalHeight = 768.0f;
	Vector3 scale;
	
	// Use this for initialization
	void Start () 
	{
		scale.x = Screen.width/originalWidth; 
    	scale.y = Screen.height/originalHeight; 
    	scale.z = 1;	
	}
	
	// Update is called once per frame
	void Update () 
	{
	
	}
	
	void OnGUI()
	{
		Matrix4x4 svMat = GUI.matrix;
	    
	    GUI.matrix = Matrix4x4.TRS(Vector3.zero, Quaternion.identity, scale);
		
		//TODO:all gui calls will be scaled based on the original width and height
		
		GUI.matrix = svMat;
	}
}

This will scale all GUI and GUILayout calls. I suggest sticking with using GUIText and GUITextures. The OnGUI system is different than the GUILayer(Which GUIText and GUITexture run on). OnGUI will draw on top of everything no matter what. Using the GUILayer system you can have multiple cameras and have 3D objects draw on top of GUI object.

maybe GUIText is what youre looking for?

http://docs.unity3d.com/Documentation/Components/class-GuiText.html