Topic: (SOURCE) Damage Bar Behind life bar
This a very simple way to create a damage bar behind our life bar. UFE by default works like street fighter 4 and has no such display, but with this you can have a damage bar like SF3, wich starts to drop as soon as damage is taken.
First, open DefaultBattleGUI.cs
and in the first class default battle gui below
public Image lifeBar;
add
public Image lifeBarDamage;
then in #region public instance properties, below
public float lifeUpSpeed = 900f;
add:
public float lifeDownDamageSpeed = 50f;
then, after
if (this.player2GUI != null && this.player2GUI.lifeBar != null){
this.player2GUI.lifeBar.fillAmount = this.player2.targetLife / this.player2.totalLife;
}
add:
//lifeBarDamage
if (this.player1GUI != null && this.player1GUI.lifeBarDamage != null){
this.player1GUI.lifeBarDamage.fillAmount = this.player1.targetLifeDamage / this.player1.totalLife;
}
if (this.player2GUI != null && this.player2GUI.lifeBar != null){
this.player2GUI.lifeBar.fillAmount = this.player2.targetLife / this.player2.totalLife;
}
if (this.player2GUI != null && this.player2GUI.lifeBarDamage != null){
this.player2GUI.lifeBarDamage.fillAmount = this.player2.targetLifeDamage / this.player2.totalLife;
}
then after
if (this.player1.targetLife > UFE.GetPlayer1ControlsScript().currentLifePoints){
this.player1.targetLife -= this.lifeDownSpeed * deltaTime;
if (this.player1.targetLife < UFE.GetPlayer1ControlsScript().currentLifePoints)
this.player1.targetLife = (float)UFE.GetPlayer1ControlsScript().currentLifePoints;
}
add:
if (this.player1.targetLifeDamage > UFE.GetPlayer1ControlsScript().currentLifePoints){
this.player1.targetLifeDamage -= this.lifeDownDamageSpeed * deltaTime;
if (this.player1.targetLifeDamage < UFE.GetPlayer1ControlsScript().currentLifePoints)
this.player1.targetLife = (float)UFE.GetPlayer1ControlsScript().currentLifePoints;
}
if (this.player1.targetLifeDamage < UFE.GetPlayer1ControlsScript().currentLifePoints){
this.player1.targetLifeDamage += this.lifeUpSpeed * deltaTime;
if (this.player1.targetLifeDamage > UFE.GetPlayer1ControlsScript().currentLifePoints)
this.player1.targetLifeDamage = (float)UFE.GetPlayer1ControlsScript().currentLifePoints;
}
and after
// Animate life points when it goes down (P2)
if (this.player2.targetLife > UFE.GetPlayer2ControlsScript().currentLifePoints){
this.player2.targetLife -= this.lifeDownSpeed * deltaTime;
if (this.player2.targetLife < UFE.GetPlayer2ControlsScript().currentLifePoints)
this.player2.targetLife = (float)UFE.GetPlayer2ControlsScript().currentLifePoints;
}
add:
if (this.player2.targetLifeDamage > UFE.GetPlayer2ControlsScript().currentLifePoints){
this.player2.targetLifeDamage -= this.lifeDownDamageSpeed * deltaTime;
if (this.player2.targetLifeDamage < UFE.GetPlayer2ControlsScript().currentLifePoints)
this.player2.targetLife = (float)UFE.GetPlayer2ControlsScript().currentLifePoints;
}
if (this.player2.targetLifeDamage < UFE.GetPlayer2ControlsScript().currentLifePoints){
this.player2.targetLifeDamage += this.lifeUpSpeed * deltaTime;
if (this.player2.targetLifeDamage > UFE.GetPlayer2ControlsScript().currentLifePoints)
this.player2.targetLifeDamage = (float)UFE.GetPlayer2ControlsScript().currentLifePoints;
}
Now, go to BattleGUI.cs and in the first class below
public float targetLife;
add:
public float targetLifeDamage;
and in the #region protected instance methods section, below
this.player1.targetLife = player1.myInfo.lifePoints;
add:
this.player1.targetLifeDamage = player1.myInfo.lifePoints;
and below:
this.player2.targetLife = player2.myInfo.lifePoints;
add:
this.player2.targetLifeDamage = player2.myInfo.lifePoints;
That's all from the code, now you can open your battle GUI prefab and a new field will be available to select an image to work as a life damage display. You can simply duplicate your original life bar, put the duplicate behind it and change the image or the color, and drag it to the damage life bar field. there's one for player 1 and player 2. also you'll see a new value called slide damage down speed, wich is how fast the damage bar is droping. By default is set to 50, so is slower than the life bar drop speed, and you can see the damage behind it.
Hope you find this useful!