multiple choice question in Unity

Hi I'm new to Unity, and have very limite programming skills. I want to make a question window, in the window it will have one question, the question will have four different answers. If the use select the wrong answer, "Try angain" will appear; if the use select the right answer, "Well done" will appear, and a close button will show up.

Can anyone give me some ideas? Thanks very much

===========================================

EDIT: Hi Bravini thank you very much

Sorry,I only can understand very simple code, so I tried to modified your code, but the last part not working, could you point out what's wrong? Thanks very much

var textToShow1: String;
var textToShow2: String;
var textToShow3: String;
var textToShow4: String;

function OnGUI () {

  GUI.Label (Rect (20, 10, 500, 30), "-------------Q1?-------------------");

  GUI.Label (Rect (120, 40, 500, 30), textToShow1); 
  GUI.Label (Rect (120, 70, 500, 30), textToShow2); 
  GUI.Label (Rect (120, 100, 500, 30), textToShow3); 
  GUI.Label (Rect (120, 130, 500, 30), textToShow4); 

  if(GUI.Button(Rect(20,40,80,20),"A1")) { 
            textToShow1="Try Again";
        }
  if(GUI.Button(Rect(20,70,80,20),"A2")) { 
            textToShow2="Try Again";
        }
  if(GUI.Button(Rect(20,100,80,20),"A3")) { 
            textToShow3="Try Again";
        }

  if (GUI.Button(Rect(20,130,80,20),"A4")){

            textToShow4 ="Well done!";
            if(GUI.Button(Rect(20,160,80,20),"close")){
            Application.LoadLevel (1);
            }
          }

}

=======================================================

EDIT: I've fixed the problem. Thanks! At least I've learned something =)

var isQuestionaryOn = false;

function OnGUI(){
    if (GUI.Button(Rect(20,130,80,20),"A4")){
    isQuestionaryOn=true;
    textToShow4 ="Well done!";
    }   
    if (isQuestionaryOn){
         if(GUI.Button(Rect(20,160,80,20),"Back")){
    Application.LoadLevel(1);
    }
}   

}

there are many ways to do this, a simple though not very elegant wqay is to nest GUI.buttons. a snippet for you to arrange your commands would be(in js) :

var textToShow: String;

<p>function OnGUI () {</p>

<blockquote>
  <p>GUI.Label (Rect (10, 10, 100, 20), textToShow);
  if (isQuestionaryOn) {//your boolean variable that makes the questionary appear
  if(GUI.Button(Rect(10,10,50,50),"wrongButton")) { //wrong button is a text, name it like the answer you want</p>
  
  <blockquote>
    <p>textToShow="Try Again";</p>
  </blockquote>
  
  <p>}</p>
</blockquote>

<p>if (GUI.Button(Rect(10,10,50,50),"RighButton")){</p>

<blockquote>
  <blockquote>
    <p>textToShow ="Well done!";</p>
    
    <p>if(GUI.Button(Rect(10,10,50,50),"close")){</p>
    
    <blockquote>
      <blockquote>
        <p>yield new WaitForSeconds(5);
        Application.Quit(); //this will close the game</p>
      </blockquote>
    </blockquote>
    
    <p>}</p>
  </blockquote>
</blockquote>

<p>}</p>

<p>}</p>

this could also be done with GUI.BeginGroup or with GUITexture objects to use like buttons, if you want something fancier.

http://unity3d.com/support/documentation/ScriptReference/GUI.BeginGroup.html

http://unity3d.com/support/documentation/Components/gui-Controls.html

The most straightforward solution would probably be to use OnGUI() and GUI controls for this.

For the question itself, you can use the 'label' control. For the answers, you could use (e.g.) the 'selection grid' control or a set of 'button' controls. For actions such as 'try again' or 'close', you can use the 'button' control. Keep track of the current state ('question', 'try again', or 'close'), and create appropriate controls in your OnGUI() function depending on the current state. Then, switch between states as appropriate based on user actions.

Unless I've missed something, that should cover what you described in your post.

Edit: I usually try to avoid giving complete code examples, but that hasn't been working out for me so well lately, so here's some example code (C#). No guarantee of correctness, but I've tested it and it seems to work as expected. Formatting, layout, etc. are up to you, but this implements the basic functionality that I described above:

using UnityEngine;

public class MultipleChoice : MonoBehaviour
{
    public string question;
    public string[] answers;
    public int correctAnswer; // Note that this is a zero-based index

    enum State { Question, TryAgain, Close };

    State state = State.Question;

    void OnGUI()
    {
        switch (state) {
            case State.Question:
                DoQuestion();
                break;
            case State.TryAgain:
                DoTryAgain();
                break;
            case State.Close:
                DoClose();
                break;
        }
    }

    void DoQuestion()
    {
        GUILayout.Label(question);
        for (int i = 0; i < answers.Length; ++i) {
            if (GUILayout.Button(answers*)) {*
 *if (i == correctAnswer) {*
 *state = State.Close;*
 *} else {*
 *state = State.TryAgain;*
 *}*
 *}*
 *}*
 *}*
 *void DoTryAgain()*
 *{*
 *GUILayout.Label("Wrong answer.");*
 *if (GUILayout.Button("Press to try again...")) {*
 *state = State.Question;*
 *}*
 *}*
 *void DoClose()*
 *{*
 *GUILayout.Label("Correct!");*
 *if (GUILayout.Button("Close")) {*
 *// Whatever you want to do here (e.g. call Application.Quit()).*
 *}*
 *}*
*}*
*```*
*<p>Edit: Adding a simplified version in UnityScript, as requested. Please note that I don't use UnityScript myself, and as such I can't guarantee that the following code follows all UnityScript 'best practices'. However, it does compile and run, and behaves the same as the C# version as far as I can tell.</p>*
*<p>Here's the code:</p>*
*```*
*var question : String;*
*var answers : String[];*
*var correctAnswer : int;*
*enum State { Question, TryAgain, Close };*
*private var state : State = State.Question;*
*function OnGUI()*
*{*
 *if (state == State.Question) {*
 *GUILayout.Label(question);*
 *for (i = 0; i < answers.Length; ++i) {*
 _if (GUILayout.Button(answers*)) {*_
 _*if (i == correctAnswer) {*_
 _*state = State.Close;*_
 _*} else {*_
 _*state = State.TryAgain;*_
 _*}*_
 _*}*_
 _*}*_
 _*} else if (state == State.TryAgain) {*_
 _*if (GUILayout.Button("Wrong answer. Click this button to try again...")) {*_
 _*state = State.Question;*_
 _*}*_
 _*} else if (state == State.Close) {*_
 _*if (GUILayout.Button("Correct! Click this button to close...")) {*_
 _*Application.Quit();*_
 _*}*_
 _*}*_
_*}*_
_*```*_