Hi all!
I’m searching a particular Health Bar like Diablo Style, a Circular Health.
Is there a possiblity to implement this?
Is like this:
Hi all!
I’m searching a particular Health Bar like Diablo Style, a Circular Health.
Is there a possiblity to implement this?
Is like this:
This technique will work for any shape.
–Eric
Yes, it is possible.
Place the script in an Empty GameObject
Put the textures:
BackGround: It is your image of life.
Foreground: is the image that will be placed on top.
var x = 0;
var y = 0;
var w = 0;
var h = 0;
var bg : Texture2D;
var fg : Texture2D;
var val : float;
function OnGUI () {
// Create one Group to contain both images
// Adjust the first 2 coordinates to place it somewhere else on-screen
GUI.BeginGroup(Rect(x,y,w,h));
// Draw the background image
if (bg != null)
{
GUI.DrawTexture(Rect(0,0,w,h), bg);
}
// Create a second Group which will be clipped
// We want to clip the image and not scale it, which is why we need the second Group
GUI.BeginGroup(Rect(0,0,w,(val * h)));
// Draw the foreground image
GUI.DrawTexture(Rect(0,0,w,h), fg);
// End both Groups
GUI.EndGroup();
GUI.EndGroup();
}
Thank you very much dudes!
I’ve found a particular code that is perfect for me and is this:
var PGHealth:float;
var PGMaxHealth:float;
var bgImage: Texture2D;
var fgImage: Texture2D;
var HealtMana_Level: float;
var rectTop: float;
var rectLeft: float;
function Update()
{
rectLeft=0;
rectTop=Screen.height-bgImage.height;
if(PGHealth>0)
{
HealtMana_Level=PGHealth/PGMaxHealth;
}
else
{
Debug.Log("Died");
}
}
function OnGUI()
{
if(PGHealth>0)
{
GUI.DrawTexture(new Rect(rectLeft, rectTop, bgImage.width, bgImage.height), bgImage);
var fillHeight: float = bgImage.height * HealtMana_Level;
var heightDiff: float = bgImage.height - fillHeight;
GUI.BeginGroup(new Rect(rectLeft, rectTop + heightDiff, bgImage.width, fillHeight));
GUI.DrawTexture(new Rect(0, -heightDiff, bgImage.width, bgImage.height), fgImage);
GUI.EndGroup();
}
}
I don’t think it will run very good on iphone given its a gui call.
I would just draw a textured quad and adjust the uv’s along with the quad’s height.