Add Hitmarker HUD asset, animation and Enemy Hit Delegate

This commit is contained in:
Louis Hobbs 2023-08-08 22:31:37 +01:00
parent 1fb9930791
commit 2a33897198
5 changed files with 26 additions and 2 deletions

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

Binary file not shown.

View File

@ -342,6 +342,8 @@ void APlayerCharacter::ProcessHits(TArray<FHitResult> hits)
{
healthComponent->TakeDamage(Hit.GetActor(), CurrentWeapon->GetWeaponProperties()->WeaponDamage, nullptr,
GetController(), this);
OnEnemyHit.ExecuteIfBound();
}
}
}

View File

@ -19,6 +19,8 @@
class UInputAction;
class UInputMappingContext;
DECLARE_DELEGATE(FOnEnemyHitDelegate)
/**
*
*/
@ -61,6 +63,8 @@ public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
TSubclassOf<class UUserWidget> PlayerHUD;
FOnEnemyHitDelegate OnEnemyHit;
protected:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
float SprintSpeedMultiplier = 2.0f;

View File

@ -12,6 +12,7 @@ void UPlayerHUDWidget::NativeConstruct()
if (player)
{
player->OnFired.BindUFunction(this, "ExpandCrosshair");
player->OnEnemyHit.BindUFunction(this, "ShowHitMarker");
}
}
@ -25,3 +26,11 @@ void UPlayerHUDWidget::ExpandCrosshair()
PlayAnimation(CrosshairFired, 0.0f, 1, EUMGSequencePlayMode::Forward, playbackSpeed);
}
}
void UPlayerHUDWidget::ShowHitMarker()
{
if (RevealHitmarker)
{
PlayAnimation(RevealHitmarker, 0.0f, 1, EUMGSequencePlayMode::Forward, 1.0f);
}
}

View File

@ -26,6 +26,9 @@ public:
UFUNCTION()
void ExpandCrosshair();
UFUNCTION()
void ShowHitMarker();
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UTextBlock* HealthText;
@ -47,6 +50,12 @@ public:
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UImage* CrosshairImage;
UPROPERTY(BlueprintReadWrite, meta = (BindWidget))
UImage* HitmarkerImage;
UPROPERTY(Transient, meta = (BindWidgetAnim))
UWidgetAnimation* CrosshairFired;
UPROPERTY(Transient, meta = (BindWidgetAnim))
UWidgetAnimation* RevealHitmarker;
};