UI & Widgets

 Unreal

virtual void NativeConstruct() override;

bool UTestWidget::Initialize() { MyTextBlock_Name->SetText(FText::FromName("Player"));//UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) class UTextBlock* MyTextBlock_Name;

                 return true; }

void UTestWidget::NativeConstruct() { MyButton->OnClicked.AddDynamic(this, &UTestWidget::GamePause);//UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) class UButton* MyButton_Pause;

                 if(EnemyRange < 100) MyTextBlock_String->SetText(FText::FromName("Alert! : Enemy Near, You"));//UPROPERTY(BlueprintReadWrite, meta = (BindWidget)) class UTextBlock* MyTextBlock_String;

}

void UTestWidget::GamePause() { class UGameplayStatics::SetGamePaused(GetWorld(), true); }

//AMyHUD.h with #include "GameFramework/HUD.h" 

UPROPERTY(EditDefaultsOnly) TSubclassOf<class UUserWidget>  theTestWidget;

void AMyHUD::PortWidget() { 

                                UTestWidget* theTestWidget = Cast<UTestWidget>(CreateWidget(GetWorld(), theTestWidget));//#include "Blueprint/UserWidget.h", #include "Blueprint/WidgetTree.h"

theTestWidget->AddToViewport();//Not Required only on HUD class on player, GaMode, etc Also work PortWidget

Unity

    public Button btun;//using UnityEngine.UI;

    public Text txt;

    void Start() => txt.text = "Main Menu";

    public void Btun() => Application.LoadLevel("NewLevel");

Comments

Popular posts from this blog

Open Level

Animation

Play Sound