I create a GUI window and wanna use it as a Q&A interaction.Pls see following scripts.
The function is When I click A, another GUILayout displays as “Congratulations”. But during the test, the layout is not changed after I click A, thought the Debug.Log appears.
Could someone help me fix this out?
var windowRect : Rect = Rect (10,10,260,320);
var tex : Texture;
function OnGUI ()
{
windowRect = GUI.Window(0, windowRect, DoMyWindow, "Q&A");
}
function DoMyWindow(windowID : int)
{
var buttonPressed = false;
var correct : String = "?";
GUILayout.BeginVertical("Box");
GUILayout.Label(tex);
GUILayout.Label("Question1");
GUILayout.Space(10);
GUILayout.Label("Pls choose the answer");
if (GUILayout.Button("A. use tools"))
{
buttonPressed = true;
correct = "congratulations";
}
if (GUILayout.Button("B. use water"))
{
buttonPressed = false;
}
if (GUILayout.Button("C. use flavor"))
{
buttonPressed = false;
}
GUILayout.Space(10);
if (buttonPressed == true)
{
Debug.Log("11111111111");
GUILayout.TextField(correct);
}
else if (buttonPressed == false)
{
GUILayout.TextArea("answer is " + correct);
}
GUILayout.Space(10);
GUILayout.EndVertical();
GUI.DragWindow();
}