Add HealthPickup Functionality

This commit is contained in:
Louis Hobbs 2023-06-24 15:20:50 +01:00
parent 9bf226b614
commit bbe5f04b72
2 changed files with 23 additions and 6 deletions

View File

@ -1,7 +1,5 @@
 #include "HealthPickup.h"
#include "PlayerCharacter.h"
#include "HealthPickup.h"
// Sets default values // Sets default values
@ -15,7 +13,6 @@ AHealthPickup::AHealthPickup()
void AHealthPickup::BeginPlay() void AHealthPickup::BeginPlay()
{ {
Super::BeginPlay(); Super::BeginPlay();
} }
// Called every frame // Called every frame
@ -24,3 +21,16 @@ void AHealthPickup::Tick(float DeltaTime)
Super::Tick(DeltaTime); Super::Tick(DeltaTime);
} }
void AHealthPickup::OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult)
{
const auto Player = Cast<APlayerCharacter>(OtherActor);
if (Player)
{
Player->GetHealthComponent()->IncrementHealth(Health);
}
Super::OnOverlapBegin(OverlappedComponent, OtherActor, OtherComp, OtherBodyIndex, bFromSweep, SweepResult);
}

View File

@ -1,6 +1,5 @@
#pragma once #pragma once
#include "CoreMinimal.h"
#include "Pickup.h" #include "Pickup.h"
#include "HealthPickup.generated.h" #include "HealthPickup.generated.h"
@ -9,6 +8,10 @@ class NAKATOMI_API AHealthPickup : public APickup
{ {
GENERATED_BODY() GENERATED_BODY()
public:
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
float Health = 20.0f;
public: public:
// Sets default values for this actor's properties // Sets default values for this actor's properties
AHealthPickup(); AHealthPickup();
@ -20,4 +23,8 @@ protected:
public: public:
// Called every frame // Called every frame
virtual void Tick(float DeltaTime) override; virtual void Tick(float DeltaTime) override;
virtual void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor,
UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep,
const FHitResult& SweepResult) override;
}; };