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());
|
UpdateKillCountHUD(gamemode->GetEnemyDeathCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
GetWorld()->GetTimerManager().SetTimer(pawnLifeTimeHandle, this, &AVampirePlayerController::UpdateTimerHUD, 1.0f, true,0.f);
|
||||||
|
|
||||||
if (currentPlayerHUD)
|
if (currentPlayerHUD)
|
||||||
{
|
{
|
||||||
currentPlayerHUD->AddToViewport();
|
currentPlayerHUD->AddToViewport();
|
||||||
|
@ -56,6 +58,14 @@ void AVampirePlayerController::UpdatePlayerLevelHUD(int level)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AVampirePlayerController::UpdateTimerHUD()
|
||||||
|
{
|
||||||
|
if (currentPlayerHUD)
|
||||||
|
{
|
||||||
|
currentPlayerHUD->UpdateTimerBlock(GetPawn());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AVampirePlayerController::UpdateKillCountHUD(int killCount)
|
void AVampirePlayerController::UpdateKillCountHUD(int killCount)
|
||||||
{
|
{
|
||||||
if (currentPlayerHUD)
|
if (currentPlayerHUD)
|
||||||
|
|
|
@ -24,6 +24,8 @@ private:
|
||||||
|
|
||||||
TObjectPtr<UHUDWidget> currentPlayerHUD = nullptr;
|
TObjectPtr<UHUDWidget> currentPlayerHUD = nullptr;
|
||||||
|
|
||||||
|
FTimerHandle pawnLifeTimeHandle;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
virtual void OnPossess(APawn* aPawn) override;
|
virtual void OnPossess(APawn* aPawn) override;
|
||||||
|
|
||||||
|
@ -33,6 +35,9 @@ protected:
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void UpdatePlayerLevelHUD(int level);
|
void UpdatePlayerLevelHUD(int level);
|
||||||
|
|
||||||
|
UFUNCTION()
|
||||||
|
void UpdateTimerHUD();
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void UpdateKillCountHUD(int killCount);
|
void UpdateKillCountHUD(int killCount);
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,8 +19,23 @@ void UHUDWidget::UpdateLevelBlock(int level)
|
||||||
LevelBlock->SetText(FText::FromString("LV" + FString::FromInt(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)
|
void UHUDWidget::UpdateKillBlock(int killCount)
|
||||||
|
|
|
@ -39,7 +39,7 @@ public:
|
||||||
void UpdateLevelBlock(int level);
|
void UpdateLevelBlock(int level);
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void UpdateTimerBlock();
|
void UpdateTimerBlock(APawn* pawn);
|
||||||
|
|
||||||
UFUNCTION()
|
UFUNCTION()
|
||||||
void UpdateKillBlock(int killCount);
|
void UpdateKillBlock(int killCount);
|
||||||
|
|
Loading…
Reference in New Issue