IncrementGold when Player overlaps

This commit is contained in:
baz 2024-06-24 21:42:33 +01:00
parent 2d078ec48c
commit 7f6e41cb50
2 changed files with 14 additions and 3 deletions

View File

@ -3,6 +3,10 @@
#include "GoldPickup.h"
#include "PlayerCharacter.h"
class APlayerCharacter;
void AGoldPickup::BeginPlay()
{
Super::BeginPlay();
@ -16,7 +20,9 @@ void AGoldPickup::Tick(float DeltaSeconds)
void AGoldPickup::OnBeginOverlap(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult)
{
// TODO: Add Gold to player Gold component
Super::OnBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
if (APlayerCharacter* PlayerCharacter = Cast<APlayerCharacter>(OtherActor))
{
PlayerCharacter->GetGoldComponent()->IncrementGold(Gold);
Super::OnBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
}
}

View File

@ -14,6 +14,11 @@ class VAMPIRES_API AGoldPickup : public APickup
{
GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
int Gold = 1;
protected:
virtual void BeginPlay() override;