Move timer binding to code timer
This commit is contained in:
parent
366dbbfda8
commit
a13cad7320
BIN
Content/Widgets/HUD/BP_HUDWidget.uasset (Stored with Git LFS)
BIN
Content/Widgets/HUD/BP_HUDWidget.uasset (Stored with Git LFS)
Binary file not shown.
|
@ -33,6 +33,8 @@ void AVampirePlayerController::OnPossess(APawn* aPawn)
|
|||
UpdateKillCountHUD(gamemode->GetEnemyDeathCount());
|
||||
}
|
||||
|
||||
GetWorld()->GetTimerManager().SetTimer(pawnLifeTimeHandle, this, &AVampirePlayerController::UpdateTimerHUD, 1.0f, true,0.f);
|
||||
|
||||
if (currentPlayerHUD)
|
||||
{
|
||||
currentPlayerHUD->AddToViewport();
|
||||
|
@ -56,6 +58,14 @@ void AVampirePlayerController::UpdatePlayerLevelHUD(int level)
|
|||
}
|
||||
}
|
||||
|
||||
void AVampirePlayerController::UpdateTimerHUD()
|
||||
{
|
||||
if (currentPlayerHUD)
|
||||
{
|
||||
currentPlayerHUD->UpdateTimerBlock(GetPawn());
|
||||
}
|
||||
}
|
||||
|
||||
void AVampirePlayerController::UpdateKillCountHUD(int killCount)
|
||||
{
|
||||
if (currentPlayerHUD)
|
||||
|
|
|
@ -24,6 +24,8 @@ private:
|
|||
|
||||
TObjectPtr<UHUDWidget> currentPlayerHUD = nullptr;
|
||||
|
||||
FTimerHandle pawnLifeTimeHandle;
|
||||
|
||||
protected:
|
||||
virtual void OnPossess(APawn* aPawn) override;
|
||||
|
||||
|
@ -33,6 +35,9 @@ protected:
|
|||
UFUNCTION()
|
||||
void UpdatePlayerLevelHUD(int level);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateTimerHUD();
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateKillCountHUD(int killCount);
|
||||
};
|
||||
|
|
|
@ -19,8 +19,23 @@ void UHUDWidget::UpdateLevelBlock(int level)
|
|||
LevelBlock->SetText(FText::FromString("LV" + FString::FromInt(level)));
|
||||
}
|
||||
|
||||
void UHUDWidget::UpdateTimerBlock()
|
||||
void UHUDWidget::UpdateTimerBlock(APawn* pawn)
|
||||
{
|
||||
int timeSinceCreation = FMath::FloorToInt(pawn->GetGameTimeSinceCreation());
|
||||
|
||||
FString mins = FString::FromInt(timeSinceCreation / 60);
|
||||
if (timeSinceCreation / 60 < 10)
|
||||
{
|
||||
mins = "0" + mins;
|
||||
}
|
||||
|
||||
FString secs = FString::FromInt(timeSinceCreation % 60);
|
||||
if (timeSinceCreation % 60 < 10)
|
||||
{
|
||||
secs = "0" + secs;
|
||||
}
|
||||
|
||||
TimerBLock->SetText(FText::FromString(mins + ":" + secs));
|
||||
}
|
||||
|
||||
void UHUDWidget::UpdateKillBlock(int killCount)
|
||||
|
|
|
@ -39,7 +39,7 @@ public:
|
|||
void UpdateLevelBlock(int level);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateTimerBlock();
|
||||
void UpdateTimerBlock(APawn* pawn);
|
||||
|
||||
UFUNCTION()
|
||||
void UpdateKillBlock(int killCount);
|
||||
|
|
Loading…
Reference in New Issue