This doesn’t seem to decrease on every collide. Yes I’ve set the sword to have a box collider. But nothing seems to work.
@script ExecuteInEditMode()
var healthTexture : Texture2D;
var healthBorder : Texture2D;
private static var health : int = 100;
function OnGUI () {
GUI.DrawTexture(Rect(0,Screen.height - 600,400,100), healthBorder);
//Now on top we can put Health Bar texture
var adjust : int = health * 3; //adjusting texture size (width) / health(100)
GUI.BeginGroup(Rect(135,Screen.height - 565,adjust,15));
GUI.DrawTexture(Rect(0,0,290,15), healthTexture);
GUI.EndGroup();
}
/**
Function to handle collision
*/
function OnTriggerEnter(other:Collider)
{
health -= 10;
}