Play animation when Updating Health

This commit is contained in:
baz 2024-03-10 23:07:33 +00:00
parent 5e0433905f
commit 7d8015acf0
4 changed files with 11 additions and 6 deletions

Binary file not shown.

Binary file not shown.

View File

@ -13,7 +13,8 @@ void UEnemyHealthbarUserWidget::BindOwner(AEnemyCharacter* NewOwner)
{ {
auto healthComponent = Owner->GetHealthComponent(); auto healthComponent = Owner->GetHealthComponent();
healthComponent->OnDamaged.BindUFunction(this, "UpdateHealthbar"); healthComponent->OnDamaged.BindUFunction(this, "UpdateHealthbar");
UpdateHealthbar(); float percent = Owner->GetHealthComponent()->GetCurrentHealth() / Owner->GetHealthComponent()->GetMaxHealth();
Healthbar->SetPercent(percent);
} }
} }
@ -22,6 +23,7 @@ void UEnemyHealthbarUserWidget::UpdateHealthbar()
if (Owner) if (Owner)
{ {
float percent = Owner->GetHealthComponent()->GetCurrentHealth() / Owner->GetHealthComponent()->GetMaxHealth(); float percent = Owner->GetHealthComponent()->GetCurrentHealth() / Owner->GetHealthComponent()->GetMaxHealth();
Healthbar->SetPercent(percent); Healthbar->SetPercent(percent);
PlayAnimation(RevealHealthbar);
} }
} }

View File

@ -21,6 +21,9 @@ public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UProgressBar* Healthbar; UProgressBar* Healthbar;
UPROPERTY(Transient, meta = (BindWidgetAnim))
UWidgetAnimation* RevealHealthbar;
AEnemyCharacter* Owner; AEnemyCharacter* Owner;
public: public: