95 - Health

This commit is contained in:
Kingsmedia 2022-05-07 11:04:11 +02:00
parent 4ef9d3306a
commit ce6d62f323
8 changed files with 77 additions and 0 deletions

Binary file not shown.

View File

@ -53,6 +53,7 @@ void ABlasterCharacter::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& Ou
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
DOREPLIFETIME_CONDITION(ABlasterCharacter, OverlappingWeapon, COND_OwnerOnly);
DOREPLIFETIME(ABlasterCharacter, Health);
}
void ABlasterCharacter::OnRep_ReplicatedMovement()
@ -401,6 +402,11 @@ float ABlasterCharacter::CalculateSpeed()
return Velocity.Size();
}
void ABlasterCharacter::OnRep_Health()
{
}
void ABlasterCharacter::SetOverlappingWeapon(AWeapon* Weapon)
{
if (OverlappingWeapon)

View File

@ -92,6 +92,17 @@ private:
float ProxyYaw;
float TimeSinceLastMovementReplication;
float CalculateSpeed();
// Health
UPROPERTY(EditAnywhere, Category= "Player Stats")
float MaxHealth = 100.f;
UPROPERTY(ReplicatedUsing = OnRep_Health, VisibleAnywhere, Category= "Player Stats")
float Health = 100.f;
UFUNCTION()
void OnRep_Health();
public:
void SetOverlappingWeapon(AWeapon* Weapon);

View File

@ -3,6 +3,26 @@
#include "BlasterHUD.h"
#include "CharacterOverlay.h"
#include "Blueprint/UserWidget.h"
void ABlasterHUD::BeginPlay()
{
Super::BeginPlay();
AddCharacterOverlay();
}
void ABlasterHUD::AddCharacterOverlay()
{
APlayerController* PlayerController = GetOwningPlayerController();
if (PlayerController && CharacterOverlayClass)
{
CharacterOverlay = CreateWidget<UCharacterOverlay>(PlayerController, CharacterOverlayClass);
CharacterOverlay->AddToViewport();
}
}
void ABlasterHUD::DrawHUD()
{
Super::DrawHUD();

View File

@ -32,6 +32,16 @@ class BLASTER_API ABlasterHUD : public AHUD
public:
virtual void DrawHUD() override;
UPROPERTY(EditAnywhere, Category = "Player Stats")
TSubclassOf<class UUserWidget> CharacterOverlayClass;
class UCharacterOverlay* CharacterOverlay;
protected:
virtual void BeginPlay() override;
void AddCharacterOverlay();
private:
FHUDPackage HUDPackage;

View File

@ -0,0 +1,5 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "CharacterOverlay.h"

View File

@ -0,0 +1,25 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "CharacterOverlay.generated.h"
/**
*
*/
UCLASS()
class BLASTER_API UCharacterOverlay : public UUserWidget
{
GENERATED_BODY()
public:
UPROPERTY(meta = (BindWidget))
class UProgressBar* HealthBar;
UPROPERTY(meta = (BindWidget))
class UTextBlock* HealthText;
};