diff --git a/Source/Blaster/Character/BlasterCharacter.h b/Source/Blaster/Character/BlasterCharacter.h index 3605946..9ef8b30 100644 --- a/Source/Blaster/Character/BlasterCharacter.h +++ b/Source/Blaster/Character/BlasterCharacter.h @@ -168,4 +168,6 @@ public: FORCEINLINE UCameraComponent* GetFollowCamera() const { return FollowCamera; } FORCEINLINE bool ShouldRotateRootBone() const { return bRotateRootBone; } FORCEINLINE bool IsEliminated() const { return bEliminated; } + FORCEINLINE float GetHealth() const { return Health; } + FORCEINLINE float GetMaxHealth() const { return MaxHealth; } }; diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.cpp b/Source/Blaster/PlayerController/BlasterPlayerController.cpp index 9a5384e..f4580bf 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.cpp +++ b/Source/Blaster/PlayerController/BlasterPlayerController.cpp @@ -3,6 +3,7 @@ #include "BlasterPlayerController.h" +#include "Blaster/Character/BlasterCharacter.h" #include "Blaster/HUD/BlasterHUD.h" #include "Blaster/HUD/CharacterOverlay.h" #include "Components/ProgressBar.h" @@ -16,6 +17,16 @@ void ABlasterPlayerController::BeginPlay() BlasterHUD = Cast(GetHUD()); } +void ABlasterPlayerController::OnPossess(APawn* InPawn) +{ + Super::OnPossess(InPawn); + + if (const ABlasterCharacter* BlasterCharacter = Cast(InPawn)) + { + SetHUDHealth(BlasterCharacter->GetHealth(), BlasterCharacter->GetMaxHealth()); + } +} + void ABlasterPlayerController::SetHUDHealth(float Health, float MaxHealth) { BlasterHUD = BlasterHUD == nullptr ? Cast(GetHUD()) : BlasterHUD; diff --git a/Source/Blaster/PlayerController/BlasterPlayerController.h b/Source/Blaster/PlayerController/BlasterPlayerController.h index ea36af0..37a51f9 100644 --- a/Source/Blaster/PlayerController/BlasterPlayerController.h +++ b/Source/Blaster/PlayerController/BlasterPlayerController.h @@ -17,6 +17,7 @@ class BLASTER_API ABlasterPlayerController : public APlayerController public: void SetHUDHealth(float Health, float MaxHealth); + virtual void OnPossess(APawn* InPawn) override; protected: