Search Unity

Life bar in UnityGUI?

Discussion in 'Immediate Mode GUI (IMGUI)' started by nickavv, Feb 10, 2008.

  1. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    Has anybody made a graphical life bar with UnityGUI yet? I am attempting to make one, by putting a GUI Box with the bar housing, and then a GUI Label with the bar inside image (which completely fills up the empty part of the box), and then scaling the size of the label, hoping that the end part of the image would get cut off. No such luck however. Any ideas?
     
  2. Jessy

    Jessy

    Joined:
    Jun 7, 2007
    Posts:
    7,325
  3. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    I haven't. I'll have to give that a shot. :)
     
  4. careyagimon

    careyagimon

    Joined:
    Dec 20, 2007
    Posts:
    209
    This is what I am using currently:


    Code (csharp):
    1. GUI.Box (Rect (70, 10, Mathf.Clamp01(hitPointsCurrent / hitPointsMax) * (Screen.width - 140), 20), "", GUIstyle);
     
  5. jeremyace

    jeremyace

    Joined:
    Oct 12, 2005
    Posts:
    1,661
    I am doing basically the same for an in-game progress bar. Works very well. You just set your progress bar's BG image in a new GUIStyle for it.

    Code (csharp):
    1.  
    2. healthBarStyle.normal.background = healthBarTexture;
    3.  
    -Jeremy
     
  6. nickavv

    nickavv

    Joined:
    Aug 2, 2006
    Posts:
    1,801
    I used the example shown on the UnityGUI page, and with some tweaking to my likings, I was able to get it just the way I want it.

    Thanks for showing me that Jessy. :)