- Home /
Healthbar is over play dead Animation
I want to healthbar over can play animation. How can I do?
this my healthbar.js
var health100:Texture2D; var health95:Texture2D; var health90:Texture2D; var health85:Texture2D; var health80:Texture2D; var health75:Texture2D; var health70:Texture2D; var health65:Texture2D; var health60:Texture2D; var health55:Texture2D; var health50:Texture2D; var health45:Texture2D; var health40:Texture2D; var health35:Texture2D; var health30:Texture2D; var health25:Texture2D; var health20:Texture2D; var health15:Texture2D; var health10:Texture2D; var health5:Texture2D; var health0:Texture2D;
function OnGUI () { if (GeneralVars.blood <=100 &&GUI.Button (Rect (450,425,50,25), "restart")) { GeneralVars.blood = 100; Application.LoadLevel(1); script = GetComponent(HealthBarPicture); script.DoSomething (HealthBarPicture); } }
function Update () {
if(GeneralVars.blood ==100) this.guiTexture.texture = health100;
else if(GeneralVars.blood >=95 && GeneralVars.blood <100) this.guiTexture.texture = health95; else if(GeneralVars.blood >=90 && GeneralVars.blood <95) this.guiTexture.texture = health90;
else if(GeneralVars.blood >=85 && GeneralVars.blood <90) this.guiTexture.texture = health85; else if(GeneralVars.blood >=80 && GeneralVars.blood <85) this.guiTexture.texture = health80;
else if(GeneralVars.blood >=75 && GeneralVars.blood <80) this.guiTexture.texture = health75; else if(GeneralVars.blood >=70 && GeneralVars.blood <75) this.guiTexture.texture = health70;
else if(GeneralVars.blood >=65 && GeneralVars.blood <70) this.guiTexture.texture = health65; else if(GeneralVars.blood >=60 && GeneralVars.blood <65) this.guiTexture.texture = health60;
else if(GeneralVars.blood >=55 && GeneralVars.blood <60) this.guiTexture.texture = health55; else if(GeneralVars.blood >=50 && GeneralVars.blood <55) this.guiTexture.texture = health50;
else if(GeneralVars.blood >=45 && GeneralVars.blood <50) this.guiTexture.texture = health95; else if(GeneralVars.blood >=40 && GeneralVars.blood <45) this.guiTexture.texture = health40;
else if(GeneralVars.blood >=35 && GeneralVars.blood <40) this.guiTexture.texture = health95; else if(GeneralVars.blood >=30 && GeneralVars.blood <35) this.guiTexture.texture = health30;
else if(GeneralVars.blood >=25 && GeneralVars.blood <30) this.guiTexture.texture = health25; else if(GeneralVars.blood >=20 && GeneralVars.blood <25) this.guiTexture.texture = health20;
else if(GeneralVars.blood >=15 && GeneralVars.blood <20) this.guiTexture.texture = health15; else if(GeneralVars.blood >=10 && GeneralVars.blood <15) this.guiTexture.texture = health10;
else if(GeneralVars.blood >=5 && GeneralVars.blood <10) this.guiTexture.texture = health5;
else if(GeneralVars.blood <5 &) this.guiTexture.texture = health0; animation.Play( "dead" );
}
I Cannot play dead animation in game over. How can I do?
Apart from having the potential to be refactored and made more efficient, what is wrong with your code above? What do you want to know exactly?
Yeahhh, I not really understanding the question either?
Answer by Statement · Dec 15, 2010 at 12:32 PM
If your code otherwise works, but you won't know how to animate the change over time; This is easily done in an update or co routine.
GeneralVars.blood = Mathf.MoveTowards(GeneralVars.blood, blood, Time.deltaTime);
where blood is a variable that you set on damage. Alternatively you can change so
// private member to help track the animated blood value private var blood : float = 0;
// set the blood value to move towards GeneralVars.blood blood = Mathf.MoveTowards(blood, GeneralVars.blood, Time.deltaTime);
because I think it'll fit into your system easier. Then your gui code be changed;
// old style: else if(GeneralVars.blood >=55 && GeneralVars.blood <60) this.guiTexture.texture = health55;
// new style (use blood variable): else if(blood >=55 && blood <60) this.guiTexture.texture = health55;
But I really suggest you refactor your code first since it's just a pain and nightmare to work with a method that large.
Your answer
Follow this Question
Related Questions
Problem with GUI animation transitioning. 1 Answer
GUI button is moving/disappearing when animation is played 0 Answers
(Unity 4.6) Button animations 1 Answer
GUI, SpellBar and C#-related questions 1 Answer
Scrollbar Thumb Scaling 0 Answers