// menuキーが押されたら
if (this->bmenu == 1 && this->menuflag == false)
{
this->menuflag = true;
MyWidget = CreateWidget<UUserWidget>(GetWorld(), UseWidgetClass);
if (MyWidget)
{
MyWidget->AddToViewport();
}
UE_LOG(LogTemp, Warning, TEXT("Hello! IN %d"), 22);
}
// menuキーから指が離れたら
if (this->bmenu == 0 && this->menuflag == true)
{
this->menuflag = false;
if (MyWidget)
{
MyWidget->RemoveFromParent();
}
UE_LOG(LogTemp, Warning, TEXT("Hello! OUT %d"), 22);
}
Character.cppのコンストラクタ
static ConstructorHelpers::FClassFinder<UUserWidget> WidgetAsset(TEXT("/Game/FirstPerson/menu"));
if (WidgetAsset.Succeeded())
{
// Assign the class of the loaded asset to the WigetClass variable, which is a "subclass" of UUserWidget : Which our asset class is
UseWidgetClass = WidgetAsset.Class;
}