Hello,
I’m trying to put health bars above my bad guys and I want the bar to follow them and also always face the camera. I’ve watched and read a few tutorials but half of them don’t work, maybe it’s because I’m using the GUI.DrawTexture wrong.
So far I have this code which is attached to my gameobject GUITexture in the game (I basically found this code in the forum) :
public Texture myText;
public Transform target;
float x, y;
public float xOffset, yOffset;
// Update is called once per frame
void Update () {
Vector3 BarPosition;
BarPosition = Camera.main.WorldToScreenPoint (target.position);
x = BarPosition.x - xOffset;
y = Screen.height - BarPosition.y - yOffset;
Rect HPBAR = new Rect (x, y, 100, 20); // 100 and 20 Random values to test
GUI.DrawTexture (HPBAR, myText);
}
With this nothing shows up, whatever xOffset and yOffset might be. Target is supposed to by my bad guy and Texture is obviously my texture.
Any ideas ?