How to show a modal window after button click in Unity?

I am new to Unity and C# programming. I just want to know how to open a modal window on button click.

public class Buttonwindow: MonoBehaviour 
{
    public void clicked(Button button)
    {
        Debug.Log("Button click!");

    }
}

What code will be going in here to show a pop up window? Thanks!

Answers


Use yourModelWindowPanel.SetActive(true) to enable/show your Window and pass in false to the SetActive function to hide it. This could be a panel with UI components under it.

public class Buttonwindow: MonoBehaviour 
{
    public GameObject modalWindow;
    public void clicked(Button button)
    {
        Debug.Log("Button click!");
        modalWindow.SetActive(true);
    }
}

In the Scene, right click -> UI -> Canvas to create a canvas(All UI elements should be in a Canvas) Then right click in the canvas that your created and then UI-> the element that you want(Text maybe works for your purpouse)

Then as @Programmer said

public class Buttonwindow: MonoBehaviour 
{
    public GameObject modalWindow;
    public void clicked(Button button)
    {
    Debug.Log("Button click!");
    modalWindow.SetActive(true);
    }
}

Don't forget to set the modalWindow to your object in the Inspector

I can't comment due to my reputation, but this answer is only an improvement to the real answer by @Programmer.

Here is a tutorial for Unity UI.


Need Your Help

How to add AdMob interstitial ad

java android import

How to add AdMob interstitial ad?

Apache RewriteMap with wildcard condition

apache mod-rewrite url-rewriting rewritemap

I am using apache RewriteMap with a text file to map some old urls to new urls, in my file (red.map) I have