Skip to content

Instantly share code, notes, and snippets.

@ashblue
Created July 7, 2014 11:36
Show Gist options
  • Save ashblue/42fa6bcd70fe82c8b25f to your computer and use it in GitHub Desktop.
Save ashblue/42fa6bcd70fe82c8b25f to your computer and use it in GitHub Desktop.
Unity energy bar example
using UnityEngine;
using System.Collections;
public class PlayerHealth : MonoBehaviour {
Vector2 pos = new Vector2(10, 10);
Vector2 size = new Vector2(200, 16);
float barFill = 0.8f;
string barText = "Health";
public GUIStyle progress_empty;
public GUIStyle progress_full;
void OnGUI () {
// Create a group container to make positioning easier
GUI.BeginGroup(new Rect(pos.x, pos.y, size.x, size.y));
// Draw the background and fill
GUI.Box(new Rect(0, 0, size.x, size.y), barText, progress_empty);
GUI.Box(new Rect(0, 0, size.x * barFill, size.y), barText, progress_full);
GUI.EndGroup();
}
void Update () {
// Poll the player's health from stats object here
// barFill = 8 / 10;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment