|
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
(comments are locked)
|
|
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);
}
owh, its awesome. Thank you very much, can i call you the master =)?
Jul 08 '12 at 06:39 PM
m4s4m0r1
(comments are locked)
|
