So, i tried to make an health bar and the best method i've found is the one in the script. I'm trying to make a vertical health bar, but it only drecrease is size from the bottom to the top and i would like to make from top to bottom. And i would also ask if anyone can tell me how to make it a solid color, i've already search in forum, api and google but i can't find a solution.
I'd be gratefull if someone could help me.
script:
static var curHp : int = 100;
static var maxHp : int = 100;
public var x = 0;
public var y = 0;
var mat : Material;
var texture1 : Texture2D;
var lifeback1 : Texture2D;
var lifeback2 : Texture2D;
function Start () {
//healthRegen();
}
function Update ()
{
if(curHp > maxHp){
curHp = maxHp;
}
if(curHp < 0 )
{
curHp = 0;
}
}
function DamagePlayer(damage : float){
}
function RespawnStats ()
{
curHp = maxHp;
}
function healthRegen (duration : float) {
for(i = 1;i > 0; i++)
{
yield WaitForSeconds(duration);
if(curHp < maxHp)
{
curHp++;
}else
{
break;
}
}
}
function InstantantLife (amount : int){
curHp += amount;
}
function OnGUI()
{
if(Event.current.type.Equals(EventType.Repaint)){
GUI.DrawTexture(Rect (12, 423, 160, 160), lifeback1);
GUI.DrawTexture(Rect (670, 423, 160, 160), lifeback2);
var life_bar : Rect = new Rect(x, y, -15, -curHp*1.55);
Graphics.DrawTexture(life_bar, texture1, mat);
}
}
↧