- Home /
Question by
PurpleHeartGames · Jun 18, 2011 at 04:34 PM ·
guiresizemessagemessagebox
Message Box Question(please read)
Okay, so I have a message box script that I made and everything is going perfect except sometime the text is too much for the size of the box. Is there any way I can make the box's height/width change according to how much text there is?
Comment
Answer by aldonaletto · Jun 19, 2011 at 03:48 PM
I found something in the GUI docs that can be usefull:
http://unity3d.com/support/documentation/ScriptReference/GUIStyle.CalcSize.html
It shows an example where the rect is calculated according to the label parameter:
function ProgressBar (value : float, label : String) {
var size : Vector2 = GUI.skin.GetStyle("ProgressBarText").CalcSize(GUIContent(label));
var rect : Rect = GUILayoutUtility.GetRect (size.x, Mathf.Max(size.y));
rect = Rect(rect.x + 4, rect.y, rect.width -8, rect.height);
EditorGUI.ProgressBar (rect, value, label);
EditorGUILayout.Space();
}
I've not tested this, and I think the GUI docs are somewhat incomplete and obscure, but maybe this can help you.
Answer by mammad09 · Apr 20, 2015 at 01:32 PM
this may help
void OnGUI()
{
GUI.ModalWindow(0, new Rect(Screen.width / 2 - Screen.width / 5, Screen.height / 2 - Screen.height / 4, Screen.width / 5 * 2, Screen.height / 4 + 20), DialogWindow, "");
}
private bool showDialogWindow;
public void DialogWindow(int id)
{
{
GUILayout.BeginVertical();
{
GUILayout.Label("Use this item?");
GUILayout.Space(20);
GUILayout.BeginHorizontal();
{
GUILayout.Space(20);
if (GUILayout.Button("Yes"))
{
if (selectedUseItem)
{
DoSomething();
showDialogWindow = false;
}
}
if (GUILayout.Button("No"))
showDialogWindow = false;
GUILayout.Space(20);
}
GUILayout.EndHorizontal();
}
GUILayout.EndVertical();
}
}