Add Health Damage Delegates in Characters

This commit is contained in:
Louis Hobbs 2023-06-26 18:34:57 +01:00
parent 6ad454a881
commit 7571a7fe7a
4 changed files with 31 additions and 1 deletions

View File

@ -10,6 +10,8 @@ ANakatomiCharacter::ANakatomiCharacter()
PrimaryActorTick.bCanEverTick = true;
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("Health Component"));
HealthComponent->OnDamaged.BindUFunction(this, "OnDamaged");
HealthComponent->OnDeath.BindUFunction(this, "OnDeath");
}
// Called when the game starts or when spawned
@ -218,3 +220,11 @@ void ANakatomiCharacter::CalculateHits(TArray<FHitResult>* hits)
void ANakatomiCharacter::ProcessHits(TArray<FHitResult> hits)
{
}
void ANakatomiCharacter::OnDamaged()
{
}
void ANakatomiCharacter::OnDeath()
{
}

View File

@ -83,4 +83,10 @@ protected:
virtual void CalculateHits(TArray<FHitResult>* hits);
virtual void ProcessHits(TArray<FHitResult> hits);
UFUNCTION()
virtual void OnDamaged();
UFUNCTION()
virtual void OnDeath();
};

View File

@ -8,7 +8,6 @@
#include "EnhancedInputSubsystems.h"
#include "GameFramework/CharacterMovementComponent.h"
#include "InputMappingContext.h"
#include "Destructable.h"
#include "EnemyCharacter.h"
#define COLLISION_WEAPON ECC_GameTraceChannel1
@ -300,6 +299,17 @@ void APlayerCharacter::ProcessHits(TArray<FHitResult> hits)
}
}
void APlayerCharacter::OnDamaged()
{
Super::OnDamaged();
}
void APlayerCharacter::OnDeath()
{
Super::OnDeath();
UE_LOG(LogTemp, Error, TEXT("YOU ARE DEAD!"));
}
void APlayerCharacter::WeaponSwitchingCallback(const FInputActionInstance& Instance)
{
float value = Instance.GetValue().Get<float>();

View File

@ -131,4 +131,8 @@ protected:
virtual void CalculateHits(TArray<FHitResult>* hits) override;
virtual void ProcessHits(TArray<FHitResult> hits) override;
virtual void OnDamaged() override;
virtual void OnDeath() override;
};