Add HealthPickup Functionality
This commit is contained in:
		
							parent
							
								
									9bf226b614
								
							
						
					
					
						commit
						bbe5f04b72
					
				| @ -1,7 +1,5 @@ | ||||
|  | ||||
| 
 | ||||
| 
 | ||||
| #include "HealthPickup.h" | ||||
| #include "HealthPickup.h" | ||||
| #include "PlayerCharacter.h" | ||||
| 
 | ||||
| 
 | ||||
| // Sets default values
 | ||||
| @ -15,7 +13,6 @@ AHealthPickup::AHealthPickup() | ||||
| void AHealthPickup::BeginPlay() | ||||
| { | ||||
| 	Super::BeginPlay(); | ||||
| 	 | ||||
| } | ||||
| 
 | ||||
| // Called every frame
 | ||||
| @ -24,3 +21,16 @@ void AHealthPickup::Tick(float 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); | ||||
| } | ||||
|  | ||||
| @ -1,6 +1,5 @@ | ||||
| #pragma once | ||||
| 
 | ||||
| #include "CoreMinimal.h" | ||||
| #include "Pickup.h" | ||||
| #include "HealthPickup.generated.h" | ||||
| 
 | ||||
| @ -9,6 +8,10 @@ class NAKATOMI_API AHealthPickup : public APickup | ||||
| { | ||||
| 	GENERATED_BODY() | ||||
| 
 | ||||
| public: | ||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | ||||
| 	float Health = 20.0f; | ||||
| 
 | ||||
| public: | ||||
| 	// Sets default values for this actor's properties
 | ||||
| 	AHealthPickup(); | ||||
| @ -20,4 +23,8 @@ protected: | ||||
| public: | ||||
| 	// Called every frame
 | ||||
| 	virtual void Tick(float DeltaTime) override; | ||||
| 
 | ||||
| 	virtual void OnOverlapBegin(UPrimitiveComponent* OverlappedComponent, AActor* OtherActor, | ||||
| 	                            UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, | ||||
| 	                            const FHitResult& SweepResult) override; | ||||
| }; | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user