- Home /
Gui over object?
How would i put a gui texture, such as a health bar, over an object. i want it to be able to move around with the object. im unable to find anything that could help me on the scripting reference.
Answer by daviddan2010 · Nov 18, 2010 at 07:30 AM
thanks man... this should work, but when i put the code in then a "NullRefenceExeption" keeps popping up in the debugger. any idea why? here is the code that is messing up. it's in javascript.
var player_ob : GameObject;
player_ob = GameObject.Find("Swat");
var cam : Camera;
cam = Camera.main; var cam_pos : Transform;
cam_pos = transform;
cam_pos.position = cam.WorldToViewportPoint(player_ob.transform.position);
Either you don't have an object in the scene with the name "Swat" or you have no camera with the "$$anonymous$$ain Camera" tag.
that is what i figured too, but i do have an object named swat and the only camera that i have on screen at this point is the main camera. i now took out the "cam = Camera.main" part of the code, then drug the "$$anonymous$$ain Camera" into the variable in the inspector. there are no errors in the debug, but it now won't print out the position in the GUI. the problem is definitely in the "cam_pos.position = cam.WorldToViewportPoint(player_ob.transform.position);" because when i comment that out then it prints everything else just fine.