Add Player Damaged and Death Sounds

This commit is contained in:
baz 2025-04-07 23:40:01 +01:00
parent 8af6871538
commit 4af26afe06
6 changed files with 38 additions and 2 deletions

BIN
Content/Player/BP_PlayerCharacter.uasset (Stored with Git LFS)

Binary file not shown.

BIN
Content/Sounds/Player/MS_PlayerDamaged.uasset (Stored with Git LFS) Normal file

Binary file not shown.

BIN
Content/Sounds/Player/MS_PlayerKilled.uasset (Stored with Git LFS) Normal file

Binary file not shown.

View File

@ -8,6 +8,7 @@
#include "EnhancedInputSubsystems.h" #include "EnhancedInputSubsystems.h"
#include "EXPComponent.h" #include "EXPComponent.h"
#include "GoldComponent.h" #include "GoldComponent.h"
#include "HealthComponent.h"
#include "InputMappingContext.h" #include "InputMappingContext.h"
#include "WeaponInventoryComponent.h" #include "WeaponInventoryComponent.h"
#include "Components/WidgetComponent.h" #include "Components/WidgetComponent.h"
@ -33,6 +34,9 @@ APlayerCharacter::APlayerCharacter()
void APlayerCharacter::BeginPlay() void APlayerCharacter::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
GetHealthComponent()->OnDamaged.AddDynamic(this, &APlayerCharacter::OnDamaged);
GetHealthComponent()->OnDeath.AddDynamic(this, &APlayerCharacter::OnDeath);
} }
void APlayerCharacter::Tick(float DeltaTime) void APlayerCharacter::Tick(float DeltaTime)
@ -66,3 +70,21 @@ UGoldComponent* APlayerCharacter::GetGoldComponent()
{ {
return GoldComponent; return GoldComponent;
} }
void APlayerCharacter::OnDamaged(FDamageInfo damageInfo)
{
if (OnDamagedSound)
{
UGameplayStatics::PlaySoundAtLocation(GetWorld(), OnDamagedSound, GetActorLocation());
}
}
void APlayerCharacter::OnDeath(FDamageInfo damageInfo)
{
if (OnDeathSound)
{
UGameplayStatics::PlaySoundAtLocation(GetWorld(), OnDeathSound, GetActorLocation());
}
// TODO: End the game
}

View File

@ -43,4 +43,11 @@ public:
UEXPComponent* GetEXPComponent(); UEXPComponent* GetEXPComponent();
UGoldComponent* GetGoldComponent(); UGoldComponent* GetGoldComponent();
private:
UFUNCTION()
virtual void OnDamaged(FDamageInfo damageInfo);
UFUNCTION()
virtual void OnDeath(FDamageInfo damageInfo);
}; };

View File

@ -26,6 +26,7 @@ public:
UPROPERTY(BlueprintReadWrite, EditAnywhere) UPROPERTY(BlueprintReadWrite, EditAnywhere)
float SlerpSpeed = 10.0f; float SlerpSpeed = 10.0f;
protected: protected:
UPROPERTY(VisibleAnywhere) UPROPERTY(VisibleAnywhere)
UHealthComponent* HealthComponent; UHealthComponent* HealthComponent;