I am making some kind of RTS Game, and I want to attach a blood gauge to enemies. I use code like this:
function OnGUI () {
GUI.Label (Rect (transform.position.x,transform.position.z,100,50), hpTexture);
}
but the blood gauge appear on the screen coordinate, to show at the wrong place, did I use the wrong function? Texture 2D is better? Thanks for help.
Answering my own question: this seems to work fine.
function OnGUI () {
//enemy's transform
var screenPos : Vector3 = cam.WorldToScreenPoint (transform.position);
screenPos.y = Screen.height - screenPos.y ;
GUI.Label (Rect (screenPos.x,screenPos.y, HP,10), hpTexture);
}
but still a problem, I can not resize the Label, if the Height(HP) became smaller, the width reduce as well, I can't modify the ratio.
system
3
but still a problem, I can not resize
the Label, if the Height(HP) became
smaller, the width reduce as well, I
can't modify the ratio.
if you use GUI.DrawTexture instead of GUI.Label you have control over the texture.