Hi,
I’m trying to create a healthbar above the enemies in my game.
What I have so far is something like this
Its pretty simple.
However, I am running into problems when I start to decrement the width of the healthbar (to symbolise when the enemies get hurt)
When I get into the low numbers (less than 6 or so), the healthbar actually changes direction for some reason. The following picture is the width at 32 compared with the width at 2.
This is my code:
void Start ()
{
//red
color = new Color(255, 0, 0);
texture = new Texture2D(1, 1);
texture.SetPixel(0, 0, color);
texture.Apply();
height = 5;
width = 32;
health = width;
decrement = width / 100;
healthBar = new Rect();
healthBar.size = new Vector2(width, height);
healthBar.position = new Vector2(100, 100);
}
private void OnGUI()
{
GUI.skin.box.normal.background = texture;
GUI.Box(healthBar, GUIContent.none);
}