50 lines
1.2 KiB
C++
50 lines
1.2 KiB
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "HealthPickup.h"
|
|
|
|
#include "NiagaraComponent.h"
|
|
#include "NiagaraFunctionLibrary.h"
|
|
#include "Blaster/Character/BlasterCharacter.h"
|
|
#include "Blaster/Components/BuffComponent.h"
|
|
|
|
AHealthPickup::AHealthPickup()
|
|
{
|
|
bReplicates = true;
|
|
PickupEffectComponent = CreateDefaultSubobject<UNiagaraComponent>(TEXT("PickupEffectComponent"));
|
|
PickupEffectComponent->SetupAttachment(RootComponent);
|
|
}
|
|
|
|
void AHealthPickup::OnSphereOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, UPrimitiveComponent* OtherComp, int32 OtherBodyIndex,
|
|
bool bFromSweep, const FHitResult& SweepResult)
|
|
{
|
|
Super::OnSphereOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
|
|
|
|
ABlasterCharacter* BlasterCharacter = Cast<ABlasterCharacter>(OtherActor);
|
|
if (BlasterCharacter)
|
|
{
|
|
UBuffComponent* Buff = BlasterCharacter->GetBuff();
|
|
if (Buff)
|
|
{
|
|
Buff->Heal(HealAmount, HealingTime);
|
|
}
|
|
}
|
|
|
|
Destroy();
|
|
}
|
|
|
|
void AHealthPickup::Destroyed()
|
|
{
|
|
if (PickupEffect)
|
|
{
|
|
UNiagaraFunctionLibrary::SpawnSystemAtLocation(
|
|
this,
|
|
PickupEffect,
|
|
GetActorLocation(),
|
|
GetActorRotation()
|
|
);
|
|
}
|
|
|
|
Super::Destroyed();
|
|
}
|