Hello since yesterday I started working in unity I have some good coding experience but now i have ran into a problem and i dont know how to solve.
I am currently wworkin on an HPBar and fore some reason the bar is literally getting smaller.
This is when its full
This is when it is at 90% full
This is at 80%
From like 50% you cant even see the bar please help.
This is my code
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
public Texture2D bgImage;
public Texture2D fgImage;
public float playerMaxHP = 100;
public float playerCurHP = 100;
public float hpBarLength = 512;
public float counter = 0;
void OnGUI ()
{
GUI.BeginGroup (new Rect (0,0,hpBarLength,32));
GUI.Box (new Rect (0,0,hpBarLength,32), bgImage);
GUI.BeginGroup (new Rect (0,0, playerCurHP / playerMaxHP * hpBarLength, 32));
GUI.Box (new Rect (0,0,hpBarLength,32), fgImage);
GUI.EndGroup ();
GUI.EndGroup ();
}
void Update()
{
counter++;
if(counter == 200)
{
counter = 0;
DecreesHealth(10);
}
}
void DecreesHealth(int dec)
{
playerCurHP = playerCurHP - dec;
hpBarLength =hpBarLength * (playerCurHP / (float)playerMaxHP);
}
void IncreesHealth(int inc)
{
playerCurHP = playerCurHP + inc;
hpBarLength =hpBarLength * (playerCurHP / (float)playerMaxHP);
}
}
Also does anyone know hoow to remove the black thingy behind it.
Thanks in advance.