Change HealthComponent from private to protected

This commit is contained in:
baz 2023-09-08 21:08:54 +01:00
parent 7569f2d792
commit 1023a4f2b7
2 changed files with 5 additions and 3 deletions

View File

@ -33,7 +33,6 @@ protected:
UPROPERTY(EditDefaultsOnly) UPROPERTY(EditDefaultsOnly)
float MaxDamage = 150.f; float MaxDamage = 150.f;
private:
UPROPERTY(VisibleDefaultsOnly) UPROPERTY(VisibleDefaultsOnly)
UHealthComponent* HealthComponent = nullptr; UHealthComponent* HealthComponent = nullptr;

View File

@ -19,6 +19,9 @@ AThrowable::AThrowable()
SphereComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndProbe); SphereComponent->SetCollisionEnabled(ECollisionEnabled::QueryAndProbe);
SphereComponent->SetCollisionProfileName(FName("IgnoreOnlyPawn")); SphereComponent->SetCollisionProfileName(FName("IgnoreOnlyPawn"));
SphereComponent->SetupAttachment(RootComponent); SphereComponent->SetupAttachment(RootComponent);
HealthComponent->OnDeath.BindUFunction(this, "Explode");
} }
// Called when the game starts or when spawned // Called when the game starts or when spawned
@ -38,9 +41,9 @@ void AThrowable::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor
{ {
if (OtherActor) if (OtherActor)
{ {
if (auto healthComponent = GetComponentByClass<UHealthComponent>()) if (HealthComponent)
{ {
healthComponent->TakeDamage(this, healthComponent->GetMaxHealth(), nullptr, HealthComponent->TakeDamage(this, HealthComponent->GetMaxHealth(), nullptr,
nullptr, this); nullptr, this);
} }
} }