This code is attached to an empty gameobject and displays a gui text on screen on the the same coordinates as the object. It works fine when I test the scene in the editor, but when I compile it, it says something about HandleUtility and when I checked the reference, it says that scripts using HandleUtility must be located in Assets/Editor. I move it to the right directory and reattach the script to my object, but get some other errors instead.
Is this a bug? Is there a way to fix it or is there some different, better way to display a text over an object? I fiddled around with WorldToGUIPoint, but then the coordinates of the “label” are inverted.
var scrPt: Vector3;
var nodeGUI: HandleUtility;
var hud : GUISkin;
function OnGUI() {
var scrPt = camera.main.WorldToScreenPoint (gameObject.transform.position);
if (!Mother.knata !Mother.klickeknapp)
{
GUI.Label(Rect(scrPt.x, scrPt.y, 400, 100), gameObject.name);
}
}