dimanche 21 février 2016

Changing the value of scaleX on a health bar when objects collide

I have been trying loads of different ways to make my health bar scaleX increase by 25% incrementally when it hits targets.

So far the closest I've come is with else if statements. The problem is actionscript runs through the else if statements and doesn't stop, it does all of the calculations and makes my health bar full every time I hit something. I understand why this is happening (the else if statements are becoming true as AS3 runs through them) but I don't know how to stop it. Any help is appreciated

var health:Number = 0;
var fullHealth:Number = 100;

healthBar.scaleX = health / fullHealth;



      if (healthBar.scaleX==0){
         healthBar.scaleX =+.25;

        else if (healthBar.scaleX==.25){
            healthBar.scaleX =+.50;
        else if (healthBar.scaleX==.50){
            healthBar.scaleX =+.75;
        else if (healthBar.scaleX==.75){
            healthBar.scaleX =+1;



Aucun commentaire:

Enregistrer un commentaire