Add basic Player HUD
This commit is contained in:
parent
3632cf19f0
commit
8e59d1a8b7
BIN
Content/Player/DefaultGamemode.uasset (Stored with Git LFS)
BIN
Content/Player/DefaultGamemode.uasset (Stored with Git LFS)
Binary file not shown.
BIN
Content/Player/PlayerCharacter.uasset (Stored with Git LFS)
BIN
Content/Player/PlayerCharacter.uasset (Stored with Git LFS)
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -8,7 +8,7 @@ public class Nakatomi : ModuleRules
|
|||
{
|
||||
PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs;
|
||||
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput", "FieldSystemEngine", "GeometryCollectionEngine" });
|
||||
PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "EnhancedInput", "FieldSystemEngine", "GeometryCollectionEngine", "UMG" });
|
||||
|
||||
PrivateDependencyModuleNames.AddRange(new string[] { });
|
||||
|
||||
|
|
|
@ -63,6 +63,15 @@ void APlayerCharacter::BeginPlay()
|
|||
this->Tags.Add(FName("Player"));
|
||||
}
|
||||
|
||||
if (PlayerHUD)
|
||||
{
|
||||
currentPlayerHUD = UUserWidget::CreateWidgetInstance(*GetWorld(), PlayerHUD, FName("PLayer HUD"));
|
||||
|
||||
if (currentPlayerHUD)
|
||||
{
|
||||
currentPlayerHUD->AddToViewport();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Called every frame
|
||||
|
@ -469,3 +478,23 @@ void APlayerCharacter::ClearAllTimers()
|
|||
GetWorldTimerManager().ClearTimer(FireTimerHandle);
|
||||
GetWorldTimerManager().ClearTimer(CooldownTimerHandle);
|
||||
}
|
||||
|
||||
int APlayerCharacter::GetCurrentAmmoCount()
|
||||
{
|
||||
if (CurrentWeapon == nullptr)
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return CurrentWeapon->GetAmmoCount();
|
||||
}
|
||||
|
||||
float APlayerCharacter::GetCurrentHealthCount()
|
||||
{
|
||||
if (!GetHealthComponent())
|
||||
{
|
||||
return -1;
|
||||
}
|
||||
|
||||
return GetHealthComponent()->GetCurrentHealth();
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include "Weapon.h"
|
||||
#include "Engine/EngineTypes.h"
|
||||
#include "Engine/DamageEvents.h"
|
||||
#include "Blueprint/UserWidget.h"
|
||||
#include "PlayerCharacter.generated.h"
|
||||
|
||||
class UInputAction;
|
||||
|
@ -59,6 +60,9 @@ public:
|
|||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
UInputAction* WeaponSwitchingAction;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
TSubclassOf<class UUserWidget> PlayerHUD;
|
||||
|
||||
protected:
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, BlueprintReadWrite)
|
||||
|
@ -85,6 +89,8 @@ private:
|
|||
|
||||
bool IsFiring = false;
|
||||
|
||||
class UUserWidget* currentPlayerHUD;
|
||||
|
||||
public:
|
||||
// Sets default values for this character's properties
|
||||
APlayerCharacter();
|
||||
|
@ -147,4 +153,10 @@ public:
|
|||
void WeaponCooldownHandler();
|
||||
|
||||
void ClearAllTimers();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
int GetCurrentAmmoCount();
|
||||
|
||||
UFUNCTION(BlueprintCallable)
|
||||
float GetCurrentHealthCount();
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue