33 lines
615 B
C#
33 lines
615 B
C#
using Godot;
|
|
using Godot.Collections;
|
|
|
|
namespace Newlon.Components.Zombies;
|
|
|
|
public partial class DegradingSprite : Sprite2D
|
|
{
|
|
[Export] private Armor armor;
|
|
[Export] private Array<Texture2D> degradationStages;
|
|
[Export] private Array<float> thresholdPercentage;
|
|
|
|
public override void _Ready()
|
|
{
|
|
armor.ArmorDamaged += OnArmorHPChanged;
|
|
}
|
|
|
|
private void OnArmorHPChanged(float hp)
|
|
{
|
|
float percent = armor._hp / armor.MaxHP;
|
|
for (int i = 0; i < degradationStages.Count; i++)
|
|
{
|
|
if (percent <= thresholdPercentage[i])
|
|
{
|
|
Texture = degradationStages[i];
|
|
}
|
|
else
|
|
{
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
}
|