Unity: DisplayDialogComplex Example

Last updated on September 29, 2021 Pennywise Loading... Post a comment

The example below shows you how to implement a complex dialog in Unity by using the built-in EditorUtility.DisplayDialogComplex method. Without any further ado, let’s get our hands dirty.

A Quick Note

The EditorUtility.DisplayDialogComplex method can take up to five parameters:

  • title (String): the title of the dialog
  • message (String): the content of the dialog
  • ok (String): the text on the dialog function chosen button
  • cancel (String): the text on the dialog cancel button
  • alt (String): the text on the alternative purpose button

The Example

Screenshot:

The code:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

public class ComplexDialog : MonoBehaviour
{
  void Start()
  {
    // Call the ShowDialog function after 3 seconds
    Invoke("ShowDialog", 3.0f);
  }

  void ShowDialog()
  {
    int selectedOption = EditorUtility.DisplayDialogComplex(
        title: "Warning",
        message: "Are you sure want to quit the game?",
        ok: "Yes",
        cancel: "No",
        alt: "Just Pause The Game"
    );

    if (selectedOption == 0)
    {
      Debug.Log("You chose to quit the game");
    }
    else if (selectedOption == 1)
    {
      Debug.Log("You chose to continue playing the game");
    }
    else if (selectedOption == 2)
    {
      Debug.Log("You chose to pause the game. You can resume it anytime");
    }
  }
}

Conclusion

We’ve examined an example of implementing a complex dialog in Unity. If you’d like to explore more interesting stuff about game development, take a look at the following articles:

You can also check out our C Sharp and Unity 3d topic page to see the latest tutorials and examples.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments

Related Articles