First health bar - GUI Problem refreshing it.

So I have a Beta gui bar for health. im trying to get it to “refresh” when my curr health is changed. but the top layer of 100/100 Never goes away… and my new health such like… 90 / 100 is under the original gui call.

Ya the code worked out the same. as the resource im using.

Is there a way to “refresh” the gui box. Because it is making my new rect box at the start which is not being edited or refreshed… It just recreates a new box under it later on when changed curhealth.

here is the code

using UnityEngine;
using System.Collections;

public class PlayerHealth : MonoBehaviour
{
	public int maxHealth = 100;
	public int curHealth;
	public float healthBarLength;
	

	// Use this for initialization
	void Start ()
	{
		healthBarLength = Screen.width / 2;
	}
	
	// Update is called once per frame
	void Update ()
	{
		GetCurHealth();
		if(curHealth <= 0)
		{
		//	PlayerDead();
			
		}
	}
	
	public void SetCurHealth(int adj)
	{
		curHealth += adj;
		healthBarLength = (Screen.width / 2) * (curHealth / (float)maxHealth);
	}
	
	public int GetCurHealth ()
	{
	
		
		return curHealth;
	}

	void OnGUI ()
	{
		
		GUI.Box (new Rect (10, 10, healthBarLength, 20), curHealth + "/" + maxHealth);
	}
	
}

Try:

void Update ()
    {
       GetCurHealth();
       if(curHealth <= 0)
       {
       //    PlayerDead();
       }
       SetCurHealth(10);
    }

Wow that did something unexpected! but didnt work for current problem.

But look at the health bar, when I do it manually 20/100 the 100/100 is still there.

http://s3.postimg.org/6ms6xyeqb/help2.jpg
alt text