Well, actually what i need is a “Health Bar” that scales by its X direction as WaitForSeconds keeps going.
In my game the character will enter in a area that makes him change the animation, and when he goes out of this area the “heath bar” will decrease untill 0px
I know i must use GUI.DrawTexture and ScaleMode, but he main problem is i don’t know to script it by code.
Don’t need to be perfect, i just need orientation or some part of the code.
var myRect : Rect;
var myText : Texture;
function Start()
{
myRect = Rect(*insert starting rect variable here*);
}
function Update()
{
// Example way to change bar length
myRect.width -= Time.deltaTime;
if (myRect.width < 0) {
myRect.width = 0;
}
}
function OnGUI()
{
GUI.DrawTexture(myRect, myText);
}
The above has all the concepts you need. The code in Update will shrink the bar from the right until it hits zero length, the OnGUI() code will draw it based on the changing Rect, and the Start() function will initialize its position.