Legacy Documentation: Version 5.0
Language: English
  • C#
  • JS

Script language

Select your preferred scripting language. All code snippets will be displayed in this language.

EditorUtility.DisplayDialog

Suggest a change

Success!

Thank you for helping us improve the quality of Unity Documentation. Although we cannot accept all submissions, we do read each suggested change from our users and will make updates where applicable.

Close

Sumbission failed

For some reason your suggested change could not be submitted. Please try again in a few minutes. And thank you for taking the time to help us improve the quality of Unity Documentation.

Close

Cancel

Switch to Manual
public static function DisplayDialog(title: string, message: string, ok: string, cancel: string = ""): bool;
public static bool DisplayDialog(string title, string message, string ok, string cancel = "");

Parameters

titleThe title of the message box.
messageThe text of the message.
okLabel displayed on the OK dialog button.
cancelLabel displayed on the Cancel dialog button.

Description

Displays a modal dialog.

Use it for displaying message boxes in the editor.

ok and cancel are labels to be displayed on the dialog buttons. If cancel is empty (the default), then only one button is displayed. DisplayDialog returns true if ok button is pressed.

See Also: DisplayDialogComplex function.


Dialog box that shows info on the number of objects to be placed on the surface.

#pragma strict
// Places the selected Objects on the surface of a terrain.
public class PlaceSelectionOnSurface extends ScriptableObject {
	@MenuItem("Example/Place Selection On Surface")
	static function CreateWizard() {
		var transforms = Selection.GetTransforms(SelectionMode.Deep | SelectionMode.ExcludePrefab | SelectionMode.Editable);
		if (transforms.Length > 0 && EditorUtility.DisplayDialog("Place Selection On Surface?", "Are you sure you want to place " + transforms.Length + " on the surface?", "Place", "Do Not Place")) {
			for (var transform in transforms) {
				var hit;
				if (Physics.Raycast(transform.position, -Vector3.up, hit)) {
					transform.position = hit.point;
					var randomized = Random.onUnitSphere;
					randomized = new Vector3(randomized.x, 0F, randomized.z);
					transform.rotation = Quaternion.LookRotation(randomized, hit.normal);
				}
			}
		}
	}
}
// Places the selected Objects on the surface of a terrain.

using UnityEngine; using UnityEditor;

public class PlaceSelectionOnSurface : ScriptableObject { [MenuItem ("Example/Place Selection On Surface")] static void CreateWizard () { Transform[] transforms = Selection.GetTransforms(SelectionMode.Deep | SelectionMode.ExcludePrefab | SelectionMode.Editable);

if (transforms.Length > 0 && EditorUtility.DisplayDialog("Place Selection On Surface?", "Are you sure you want to place " + transforms.Length + " on the surface?", "Place", "Do Not Place")) { foreach (Transform transform in transforms) { RaycastHit hit; if (Physics.Raycast(transform.position, -Vector3.up, out hit)) { transform.position = hit.point; Vector3 randomized = Random.onUnitSphere; randomized = new Vector3(randomized.x, 0F, randomized.z); transform.rotation = Quaternion.LookRotation(randomized, hit.normal); } } } } }