41 - Optional Challenge: Show the Player Name

This commit is contained in:
Kingsmedia 2022-04-29 23:47:41 +02:00
parent 86ff124ae4
commit b4d4ecb47e
3 changed files with 15 additions and 0 deletions

View File

@ -4,6 +4,7 @@
#include "OverheadWidget.h"
#include "Components/TextBlock.h"
#include "GameFramework/PlayerState.h"
void UOverheadWidget::SetDisplayText(FString TextToDisplay)
{
@ -37,6 +38,17 @@ void UOverheadWidget::ShowPlayerNetRole(APawn* InPawn)
SetDisplayText(RemoteRoleString);
}
void UOverheadWidget::ShowPlayerName(APawn* InPawn)
{
if (APlayerState* PlayerState = InPawn->GetPlayerState())
{
SetDisplayText(PlayerState->GetPlayerName());
} else
{
SetDisplayText("No PlayerState");
}
}
void UOverheadWidget::OnLevelRemovedFromWorld(ULevel* InLevel, UWorld* InWorld)
{
RemoveFromParent();

View File

@ -23,6 +23,9 @@ public:
UFUNCTION(BlueprintCallable)
void ShowPlayerNetRole(APawn* InPawn);
UFUNCTION(BlueprintCallable)
void ShowPlayerName(APawn* InPawn);
protected: