I created two Texture2D objects. One which contains an empty "HealthBar" image, and one that contains a full "HealthBar" image.
What I am trying to do is draw the empty bar using GUI.DrawTexture, then draw the leftmost portion of the Full texture up to the current health of the player.
The problem I am having is getting the leftmost portion of the texture. GUI.DrawTexture doesnt appear to have an overload that lets me select a source rectangle from within the texture. Graphics.DrawTexture does, but it also requires a color, Material, and borders. The results I get using it do not look very good :(
Am I going about this the wrong way? Is there a better way to accomplish this??
Thanks, -Larry
EDIT Ok, found an example elsewhere, and have figured this out for the most part. But still having a problem. See this function I created...
function DrawBar(Left:int, Top:int, BarTexture:Texture, MaxValue:float, Value:float)
{
var LocationRect:Rect = Rect(Left,Top,EmptybarTexture.width,EmptybarTexture.height);
var DrawWidth:int;
DrawWidth = EmptybarTexture.width*(Value/MaxValue);
GUI.BeginGroup (LocationRect);
GUI.DrawTexture (Rect (LocationRect), EmptybarTexture);
GUI.BeginGroup (new Rect (Left, Top, DrawWidth, EmptybarTexture.height));
GUI.DrawTexture(LocationRect, BarTexture);
GUI.EndGroup ();
GUI.Label(Rect((LocationRect.width/2)-10,Top-5,40,50),Value.ToString());
GUI.EndGroup ();
}
This expects that there is a variable in the script named EmptybarTexture and HealthbarTexture.
You would call this with...
DrawBar(0,0,HealthbarTexture,100,50);
The problem I am having now is if I make a 2nd call with the top parameter set to 10, this 2nd bar doesn't display at all.
If anyone has any ideas, please feel free to chime in :)
-Larry