Hi there.
I need help from anyone. Im new in unity i’m doing my healthbar. I’m using texture. Im not sure how am i gonna declare the texture cause i keep getting error unity texture 2d cannot convert to int. all i wanted was my healthbar to change its width as the healthcount is changing too.
here’s my script. hope someone can help me guys.
var maxHealth = 100;
var currHealth;
var damage :int = 10;
var myHealthbar:Texture2D ;// green
var healthbarWidth :int;
var myhp;
function Start () {
healthbarWidth = 100;
//var myhp=Instantiate(myHealthbar, transform.position, transform.rotation);
}
function Update()
{
if (Input.GetKeyDown(KeyCode.F8))
ApplyDamage();
}
function ApplyDamage ()
{
maxHealth = maxHealth - damage ;
healthbarWidth = maxHealth;
healthbarWidth = myHealthbar;//maxHealth * 100;
GUI.Box( Rect (10,10, 100,50), myHealthbar);
print(maxHealth);
if (maxHealth == 0)
{
die();
}
}
function die ()
{
yield WaitForSeconds(2.0);
Destroy(gameObject);
}
thanks in advance:)