Change HealthComponent from private to protected
This commit is contained in:
parent
7569f2d792
commit
1023a4f2b7
|
@ -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;
|
||||||
|
|
||||||
|
|
|
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue