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.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/UI/PlayerHUD.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/UI/PlayerHUD.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										
											BIN
										
									
								
								Content/UI/WidgetHUD.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Content/UI/WidgetHUD.uasset
									 (Stored with Git LFS)
									
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| @ -8,7 +8,7 @@ public class Nakatomi : ModuleRules | |||||||
| 	{ | 	{ | ||||||
| 		PCHUsage = PCHUsageMode.UseExplicitOrSharedPCHs; | 		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[] {  }); | 		PrivateDependencyModuleNames.AddRange(new string[] {  }); | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -63,6 +63,15 @@ void APlayerCharacter::BeginPlay() | |||||||
| 		this->Tags.Add(FName("Player")); | 		this->Tags.Add(FName("Player")); | ||||||
| 	} | 	} | ||||||
| 
 | 
 | ||||||
|  | 	if (PlayerHUD) | ||||||
|  | 	{ | ||||||
|  | 		currentPlayerHUD = UUserWidget::CreateWidgetInstance(*GetWorld(), PlayerHUD, FName("PLayer HUD")); | ||||||
|  | 
 | ||||||
|  | 		if (currentPlayerHUD) | ||||||
|  | 		{ | ||||||
|  | 			currentPlayerHUD->AddToViewport(); | ||||||
|  | 		} | ||||||
|  | 	} | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| // Called every frame
 | // Called every frame
 | ||||||
| @ -469,3 +478,23 @@ void APlayerCharacter::ClearAllTimers() | |||||||
| 	GetWorldTimerManager().ClearTimer(FireTimerHandle); | 	GetWorldTimerManager().ClearTimer(FireTimerHandle); | ||||||
| 	GetWorldTimerManager().ClearTimer(CooldownTimerHandle); | 	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 "Weapon.h" | ||||||
| #include "Engine/EngineTypes.h" | #include "Engine/EngineTypes.h" | ||||||
| #include "Engine/DamageEvents.h" | #include "Engine/DamageEvents.h" | ||||||
|  | #include "Blueprint/UserWidget.h" | ||||||
| #include "PlayerCharacter.generated.h" | #include "PlayerCharacter.generated.h" | ||||||
| 
 | 
 | ||||||
| class UInputAction; | class UInputAction; | ||||||
| @ -59,6 +60,9 @@ public: | |||||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | ||||||
| 	UInputAction* WeaponSwitchingAction; | 	UInputAction* WeaponSwitchingAction; | ||||||
| 
 | 
 | ||||||
|  | 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | ||||||
|  | 	TSubclassOf<class UUserWidget> PlayerHUD; | ||||||
|  | 
 | ||||||
| protected: | protected: | ||||||
| 
 | 
 | ||||||
| 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | 	UPROPERTY(EditDefaultsOnly, BlueprintReadWrite) | ||||||
| @ -85,6 +89,8 @@ private: | |||||||
| 
 | 
 | ||||||
| 	bool IsFiring = false; | 	bool IsFiring = false; | ||||||
| 
 | 
 | ||||||
|  | 	class UUserWidget* currentPlayerHUD; | ||||||
|  | 
 | ||||||
| public: | public: | ||||||
| 	// Sets default values for this character's properties
 | 	// Sets default values for this character's properties
 | ||||||
| 	APlayerCharacter(); | 	APlayerCharacter(); | ||||||
| @ -147,4 +153,10 @@ public: | |||||||
| 	void WeaponCooldownHandler(); | 	void WeaponCooldownHandler(); | ||||||
| 
 | 
 | ||||||
| 	void ClearAllTimers(); | 	void ClearAllTimers(); | ||||||
|  | 
 | ||||||
|  | 	UFUNCTION(BlueprintCallable) | ||||||
|  | 	int GetCurrentAmmoCount(); | ||||||
|  | 
 | ||||||
|  | 	UFUNCTION(BlueprintCallable) | ||||||
|  | 	float GetCurrentHealthCount(); | ||||||
| }; | }; | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user