- Home /
Problem is not reproducible or outdated
Show changes in healthbar
I've been able to instantiate my health bar, stamina bar and energy bar . I have a variable to handle the pixelInset.width of the prefab. How then, do I display the changes as the player takes damage and heals?
LifeWidth=_playerLife.GetComponent<GUITexture>().pixelInset.width;
//this debugs out fine.
// change is either a negative number for damage or a positive number for healing.
//first function takes in damage or healing for the int for player life, then calls the next function which is supposed to change the bar width.
public int OnChangeLife(int Change)
{
Debug.Log("Incoming Life"+CurrentPlayerLife);
CurrentPlayerLife=CurrentPlayerLife+Change;
Debug.Log("adjusted Life"+CurrentPlayerLife);
return CurrentPlayerLife;
OnChangeLifeWidth(CurrentPlayerLife, LifeWidth);
}
//This is supposed to calculate the new bar width, but it's not displaying. The calculation is made, but the bar doesn't change width. What am I missing? a Rect?
public void OnChangeLifeWidth( int CurrentPlayerLife, float LifeWidth) {
Debug.Log("Change the Width"); LifeWidth=(CurrentPlayerLife/MaxPlayerLife)*LifeWidth; Debug.Log("Length of bar" + LifeWidth);
Thanks!
Answer by Yasantha · Sep 03, 2012 at 01:14 AM
Why you call OnChangeLifeWidth(CurrentPlayerLife, LifeWidth); function after return method ??? Noting will execute after return statement. Is that the error ???
Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Creating A GUI health bar 0 Answers
How to make slider function properly after an animation? 2 Answers
Health Bar doesnt fit my float var 1 Answer