Hi all,I want to know how to make a GUI bar move relative to an game object in the scene like this picture:
thx in advance (if you have an idea or a piece of code help me plz) :).
thx exiguous, thats help me so much!!!
this is the code that solve the problem ^^.
private var screenPos:Vector3 ;
private var cam;
var aTexture : Texture;
function Awake(){
cam =GameObject.FindWithTag(“MainCamera”);
}
function OnGUI () {
screenPos = cam.camera.WorldToScreenPoint(transform.position);
print(screenPos.y);
GUI.DrawTexture(Rect(screenPos.x-30,Screen.height-screenPos.y-60,60,60), aTexture, ScaleMode.ScaleToFit, true, 10.0f);
}
is a substitute for your find.
so you can write:
screenPos = Camera.main.WorldToScreenPoint(transform.position); in OnGUI().
may be a bit more inefficient so your cache version is also ok.
thx thats help me too :).