From 7f6e41cb50a8d7605bc573909f9ac131f53d8f39 Mon Sep 17 00:00:00 2001 From: baz Date: Mon, 24 Jun 2024 21:42:33 +0100 Subject: [PATCH] IncrementGold when Player overlaps --- Source/vampires/GoldPickup.cpp | 12 +++++++++--- Source/vampires/GoldPickup.h | 5 +++++ 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Source/vampires/GoldPickup.cpp b/Source/vampires/GoldPickup.cpp index 03319ef..a51bef5 100644 --- a/Source/vampires/GoldPickup.cpp +++ b/Source/vampires/GoldPickup.cpp @@ -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(OtherActor)) + { + PlayerCharacter->GetGoldComponent()->IncrementGold(Gold); + Super::OnBeginOverlap(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult); + } } diff --git a/Source/vampires/GoldPickup.h b/Source/vampires/GoldPickup.h index fc2b354..6fdf37f 100644 --- a/Source/vampires/GoldPickup.h +++ b/Source/vampires/GoldPickup.h @@ -14,6 +14,11 @@ class VAMPIRES_API AGoldPickup : public APickup { GENERATED_BODY() +public: + + UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) + int Gold = 1; + protected: virtual void BeginPlay() override;