- Home /
Question by
MateusLog · Mar 21, 2015 at 06:45 PM ·
progress-bardecreaseminuteshealth barhealth
progress bar
I would like to make it descends from the top down but he's only decendo to right to left someone help me?
#pragma strict
var tamanhovida : Vector2 = new Vector2(10, 40);
var tamanhofome : Vector2 = new Vector2(10, 40);
var tamanhosede : Vector2 = new Vector2(10, 40);
var skin : GUISkin;
var vida : Vector2 = new Vector2(20, 20);
var barravida : float = 1;
var vidacheia : Texture2D;
var vidavazia : Texture2D;
var fome : Vector2 = new Vector2(20, 60);
var barrafome : float = 1;
var fomecheia : Texture2D;
var fomevazia : Texture2D;
var sede : Vector2 = new Vector2(50, 200);
var barrasede : float = 1;
var sedevazia : Texture2D;
var sedecheia : Texture2D;
var ReducaoVida : int = 150;
var ReducaoFome : int = 150;
var ReducaoSede : int = 100;
function Start () {
}
function Update () {
if(barrafome <= 0 && (barrasede <= 0)){
barravida -= Time.deltaTime / ReducaoVida * 2;
}
else
{
if(barrafome <= 0 || barrasede <= 0){
barravida -= Time.deltaTime / ReducaoVida;
}
}
if(barrafome >= 0){
barrafome -= Time.deltaTime / ReducaoFome;
}
if(barrafome <= 0){
barrafome = 0;
}
if(barrafome >= 1){
barrafome = 1;
}
if(barrasede >= 0){
barrasede -= Time.deltaTime / ReducaoSede;
}
if(barrasede <= 0){
barrasede = 0;
}
if(barrasede >= 1){
barrasede = 1;
}
}
function OnGUI(){
GUI.skin = skin;
GUI.BeginGroup(new Rect (vida.x, vida.y, tamanhovida.x, tamanhovida.y));
GUI.Box(Rect(0, 0, tamanhovida.x, tamanhovida.y), vidavazia);
GUI.BeginGroup(new Rect (0, 0, tamanhovida.x * barravida, tamanhovida.y));
GUI.Box(Rect(0, 0, tamanhovida.x, tamanhovida.y), vidacheia);
GUI.EndGroup();
GUI.EndGroup();
GUI.BeginGroup(new Rect (fome.x, fome.y, tamanhofome.x, tamanhofome.y));
GUI.Box(Rect(0, 0, tamanhofome.x, tamanhofome.y), fomevazia);
GUI.BeginGroup(new Rect (0, 0, tamanhofome.x * barrafome, tamanhofome.y));
GUI.Box(Rect(0, 0, tamanhofome.x, tamanhofome.y), fomecheia);
GUI.EndGroup();
GUI.EndGroup();
GUI.BeginGroup(new Rect (sede.x, sede.y, tamanhosede.x, tamanhosede.y));
GUI.Box(Rect(0, 0, tamanhosede.x, tamanhosede.y), sedevazia);
GUI.BeginGroup(new Rect (0, 0, tamanhosede.x * barrasede, tamanhosede.y));
GUI.Box(Rect(0, 0, tamanhosede.x, tamanhosede.y), sedecheia);
GUI.EndGroup();
GUI.EndGroup();
}
Comment
Answer by Kiwasi · Mar 21, 2015 at 06:46 PM
Considered using a slider in the Unity UI tools? This makes the job trivial.
Your answer
Follow this Question
Related Questions
Problem with HealthBar 1 Answer
I need some help with a Fractional Heart System? 1 Answer
How to Make Health Decrease Over Time 2 Answers