IncrementEXP when player overlaps

This commit is contained in:
baz 2024-06-24 21:42:44 +01:00
parent 7f6e41cb50
commit cafb8206e5
2 changed files with 13 additions and 6 deletions

View File

@ -3,6 +3,8 @@
#include "EXPPickup.h"
#include "PlayerCharacter.h"
void AEXPPickup::BeginPlay()
{
Super::BeginPlay();
@ -16,7 +18,9 @@ void AEXPPickup::Tick(float DeltaSeconds)
void AEXPPickup::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
// TODO: Add EXP to player EXP component
Super::OnBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
if (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
{
PlayerCharacter->GetEXPComponent()->IncrementEXP(EXP);
Super::OnBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
}
}

View File

@ -13,7 +13,10 @@ UCLASS()
class VAMPIRES_API AEXPPickup : public APickup
{
GENERATED_BODY()
public:
int EXP = 1;
protected:
virtual void BeginPlay() override;
@ -21,6 +24,6 @@ public:
virtual void Tick(float DeltaSeconds) override;
virtual void OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) override;
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) override;
};