Hello
I am trying to make a health bar. I have got the health system in place and it decreases when the car crashes but I cant figure out how to make a health bar that goes down with the health. So for example if the health is 45 then the health bar should be 45%. I know that there is a number of health bar answers out there but for some reason none of them have worked in my game.
Thank you very much in advance.
Good question, there are many ways to do it but I like this one most:
Create a GUI Texture with your image of choice. Lets say it is 250px wide and 40px high. (for simplicity) I hope it help Revised Edition:
//Add your GUITexture here
var lifeBar : GUITexture;
//What ever your life is
public var life : int = 100;
//What ever you want
private var maxWidth : int = 250;
private var pixelToLiveRatio : float;
function Start(){
pixelToLiveRatio = maxWidth/life;
}
function Update(){
//Change the pixel inset.
lifeBar.guiTexture.pixelInset.width = (life * pixelToLiveRatio);
}