x


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.

more ▼

asked Nov 18 '10 at 01:01 AM

daviddan2010 gravatar image

daviddan2010
10 3 5 8

(comments are locked)
10|3000 characters needed characters left

2 answers: sort voted first

Try this...it's for GUIText, but you can modify it to use GUITexture instead.

more ▼

answered Nov 18 '10 at 01:10 AM

Eric5h5 gravatar image

Eric5h5
80.2k 41 132 519

(comments are locked)
10|3000 characters needed characters left

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);

more ▼

answered Nov 18 '10 at 07:30 AM

daviddan2010 gravatar image

daviddan2010
10 3 5 8

Either you don't have an object in the scene with the name "Swat" or you have no camera with the "Main Camera" tag.

Nov 18 '10 at 07:34 AM Slem

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 "Main 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.

Nov 18 '10 at 07:48 AM daviddan2010
(comments are locked)
10|3000 characters needed characters left
Your answer
toggle preview:

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Topics:

x3680
x1092

asked: Nov 18 '10 at 01:01 AM

Seen: 1577 times

Last Updated: Nov 18 '10 at 01:01 AM