Compare commits

..

2 Commits

Author SHA1 Message Date
baz a25f08b832 Replace health number with symbols 2024-04-11 00:34:24 +01:00
baz 2320014f72 Add Bin Static Mesh 2024-04-10 23:43:01 +01:00
4 changed files with 35 additions and 2 deletions

BIN
Content/Assets/Bin/SM_Bin.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/UI/HUD/WidgetHUD.uasset (Stored with Git LFS)

Binary file not shown.

View File

@ -36,3 +36,28 @@ void UPlayerHUDWidget::ShowHitMarker()
PlayAnimation(RevealHitmarker, 0.0f, 1, EUMGSequencePlayMode::Forward, 1.0f); PlayAnimation(RevealHitmarker, 0.0f, 1, EUMGSequencePlayMode::Forward, 1.0f);
} }
} }
FString UPlayerHUDWidget::GetHealthbarText(APlayerCharacter* PlayerCharacter)
{
int healthbarCharacters = 5;
float normalised = PlayerCharacter->GetHealthComponent()->GetCurrentHealth() /
PlayerCharacter->GetHealthComponent()->GetMaxHealth();
float adjusted = normalised * healthbarCharacters;
int segments = FMath::RoundToInt(adjusted);
FString healthBar = FString("[");
for (int i = 0; i < segments; i++)
{
healthBar.Append("=");
}
for (int i = segments; i < healthbarCharacters; i++)
{
healthBar.Append(" ");
}
healthBar.Append("]");
return healthBar;
}

View File

@ -6,6 +6,8 @@
#include "Blueprint/UserWidget.h" #include "Blueprint/UserWidget.h"
#include <Components/TextBlock.h> #include <Components/TextBlock.h>
#include <Components/Image.h> #include <Components/Image.h>
#include "PlayerCharacter.h"
#include "PlayerHUDWidget.generated.h" #include "PlayerHUDWidget.generated.h"
@ -29,6 +31,9 @@ public:
UFUNCTION() UFUNCTION()
void ShowHitMarker(); void ShowHitMarker();
UFUNCTION(BlueprintCallable)
FString GetHealthbarText(APlayerCharacter* PlayerCharacter);
UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UTextBlock* HealthText; UTextBlock* HealthText;