-1

have such code

bool b = EditorUtility.DisplayDialog("Test",
 "Reset or continue?", "Reset", "Continue");
if (b)
{
    ResetGame();
}

but it works only in Editor and not in Game. How to replace the EditorUtility.DisplayDialog with something that works for game?

Programmer
  • 121,791
  • 22
  • 236
  • 328
user3153616
  • 49
  • 2
  • 7

1 Answers1

3

Any Unity class that includes the word "Editor" or came from the UnityEditor namespace means that the class is designed to used in the Editor only and will only work in the Editor. So EditorUtility is for Unity Editor only.

You need to implement your own Modal Window and to be able to this, you must understand basic Unity UI such as creating buttons, panels, texts. So learn the Unity basic UI first. All you need to do is to put the UI Objects in a panel then acivate/deactivate them when needed.

For example, this is your dialogue panle:

public GameObject dialoguePanel;

to show a dialogue of the UI Panel

dialoguePanel.SetActive(true);

To hide it:

dialoguePanel.SetActive(false);

You can subscribe to the dialogue's button or UI controls events dynamically with onClick.AddListener. See this post for more information on how to subscribe to UI events.

If you still can't implement your Modal Window, then follow the tutorials below as that's exactly what you are looking for.

Unity Tutorial for a generic modal Window:

MAKING A GENERIC MODAL WINDOW Part 1

MAKING A GENERIC MODAL WINDOW Part 2

MAKING A GENERIC MODAL WINDOW Part 3

Programmer
  • 121,791
  • 22
  • 236
  • 328
  • how to make your own window ? – user3153616 Apr 22 '16 at 19:15
  • @user3153616 You can call it a dialog but it can be called a modal window... It becomes a Modal window when you have a dialog with background picture and can be moved around if you want it to. The tutorials 1 to 3 will show you how. – Programmer Apr 22 '16 at 19:23