x


gameobject move in real = move in GUI

i just want to know, how can i Connect movement my GameObject with GUITexture movement ? (for example my object move to left, my GUITexture also move to the left ) Thanks

more ▼

asked Jul 08 '12 at 04:54 PM

m4s4m0r1 gravatar image

m4s4m0r1
122 2 11 20

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

1 answer: sort oldest

You can use Camera.WorldToViewportPoint: it returns the object position in viewport coordinates, which the GUITexture understands (GUITexture script):

var target: Transform; // drag here the object to follow

function Update(){
  // place the GUITexture at the target's position:
  transform.position = Camera.main.WorldToViewportPoint(target.position);
}

NOTE: Usually you want to draw the texture at some fixed offset of the target, so that it doesn't occlude the object. For GUITextures, usually it's better to define a world offset, and adjust the screen position in the Inspector, modifying the Pixel Inset fields:

var target: Transform; // drag here the object to follow
var offset: float; // world height above the target position

function Update(){
  // calculate the position including the vertical offset:
  var pos = target.position + offset * Vector3.up;
  transform.position = Camera.main.WorldToViewportPoint(pos);
}
more ▼

answered Jul 08 '12 at 05:16 PM

aldonaletto gravatar image

aldonaletto
41.3k 16 42 195

owh, its awesome. Thank you very much, can i call you the master =)?

Jul 08 '12 at 06:39 PM m4s4m0r1
(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:

x2077
x1364
x476
x60

asked: Jul 08 '12 at 04:54 PM

Seen: 472 times

Last Updated: Jul 08 '12 at 06:39 PM