newlon/scripts/entities/DegradingSprite.cs
2025-07-19 20:13:34 +05:00

33 lines
610 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 += OnZombieHPChanged;
}
private void OnZombieHPChanged(float hp)
{
float percent = hp / armor.MaxHP;
for (int i = 0; i < degradationStages.Count; i++)
{
if (percent <= thresholdPercentage[i])
{
Texture = degradationStages[i];
}
else
{
break;
}
}
}
}