Updated Interaction.cpp

Added a wait timer to close the widget once open automatically
This commit is contained in:
MH261677 2022-11-28 22:52:51 +00:00
parent 5dce4dc603
commit b5772a024c
4 changed files with 14 additions and 5 deletions

Binary file not shown.

BIN
Content/Levels/MerchantPrototype.umap (Stored with Git LFS)

Binary file not shown.

View File

@ -30,7 +30,13 @@ void AInteraction::Tick(float DeltaTime)
void AInteraction::OnInteract()
{
UUserWidget* spawnedWidget = CreateWidget<UUserWidget>(GetWorld(), Widget);
spawnedWidget->AddToViewport(0);
CurrentWidget = CreateWidget<UUserWidget>(GetWorld(), Widget);
CurrentWidget->AddToViewport(0);
FTimerHandle WidgetTimer;
GetWorldTimerManager().SetTimer(WidgetTimer, this, &AInteraction::RemoveWidget, 5.0f, false);
}
void AInteraction::RemoveWidget()
{
CurrentWidget->RemoveFromViewport();
}

View File

@ -27,5 +27,8 @@ public:
TSubclassOf<UUserWidget> Widget;
virtual void OnInteract();
virtual void RemoveWidget();
UPROPERTY()
UUserWidget* CurrentWidget;
};