- Home /
to attach a Blood gauge to enemies
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.
Answer by Lucas · Oct 30, 2010 at 03:56 PM
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.
Answer by Ilzaer · Apr 10, 2011 at 09:58 PM
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.
Your answer
Follow this Question
Related Questions
GUITexture Button? 1 Answer
GUI Texture not visible 3 Answers
rotating GUI texture by angle 2 Answers
Select part of the texture in GUI.DrawTexture 2 Answers
Sprites and minmizing memory usage 1 Answer