How to display data from array,arraylist while clicking the button?

Hello All,

I have a task like displaying questions if i click the next button.

I wrote code like this:

  using UnityEngine;
  using System.Collections;

  public class Arrayquestions : MonoBehaviour {

private Rect windowRect6 = new Rect(Screen.width/2,Screen.height/2, 600, 100);
private bool questionbool1;
public  ArrayList question,options;
public string[,] opti;
public GUIStyle newfontStyle;
private bool toggleTxt1 = false,toggleTxt2 = false,toggleTxt3 = false,toggleTxt4 = false;
string op;

void Start () {
	
 question= new ArrayList(){"A pendulum length is 20m , find the Timeperiod of the pendulum ?","A pendulum timeperiod is 10sec , find the length of the pendulum ?"};
 options=new ArrayList(){"8.965s,7.965s,10.965s,9.965s,1","15m,25m,17m,18m,2"};	
  opti= new string[,]{{"8.965s","7.965s","10.965s","9.965s","1"},{"15m","25m","17m","18m","2"}};

}

// Update is called once per frame
void OnGUI () {
	
 	if(GUI.Button(new Rect(Screen.width-(Screen.width/4),523,130,60),"Assignment"))
	{
		questionbool1 = true;
	}
	if(questionbool1)
	{
	 windowRect6 = GUI.Window(4, windowRect6, DoMyWindow6, "");	
	}
	
}
void DoMyWindow6(int windowID)
{
	 if(GUI.Button(new Rect(450,50,70,30), "NEXT"))
	{
		print ("hi click");
//foreach(string s in question)
	for (int i=0;i<2;i++)
	{
		 GUI.Label(new Rect(10,10,500,100),question*.ToString(),newfontStyle);*
  •   }*
    
  • //foreach(string o in options)*

  •   	//for(int j=0;j<4;j++)*
    
  •   //{*
    
  •   for(int i=0,j=0; i<2 && j<4; i++,j++)*
    
  •   	{*
    
  •  toggleTxt1 = GUI.Toggle(new Rect(30, 50, 100, 40), toggleTxt1, "");*
    
  •  toggleTxt2 = GUI.Toggle(new Rect(130, 50, 100, 40), toggleTxt2, "");*
    
  •  toggleTxt3 = GUI.Toggle(new Rect(250, 50, 100, 40), toggleTxt3, "");*
    
  •  toggleTxt4 = GUI.Toggle(new Rect(350, 50, 100, 40), toggleTxt4, "");*
    
  •   	}*
    
  •   //}		*
    
  •   }*
    
  • }*
    }
    If i click the NEXT button I’m not able to get the questions.

using UnityEngine;
using System.Collections;

public class Arrayq : MonoBehaviour {

    // Use this for initialization
    private Rect windowRect6 = new Rect(Screen.width/2,Screen.height/2, 600, 100);
    private bool questionbool1,questi;
    public  string[] question,options1,options2,options3,options4;
    public  ArrayList useranswers,correctanswer;
    public string[,] opti;
    public GUIStyle newfontStyle;
    private bool toggleTxt1 = false,toggleTxt2 = false,toggleTxt3 = false,toggleTxt4 = false;
    public int qno=0;
    string op;
	private int count=0;
    void Start () {
	 questi=true;
     question= new string[]{"A pendulum length is 20m , find the Timeperiod of the pendulum ?","A pendulum timeperiod is 10sec , find the length of the pendulum ?"};
     options1=new string[]{"8.965s","15m"};
	 options2=new string[]{"7.965s","25m"};
	 options3=new string[]{"10.965s","17m"};
	 options4=new string[]{"9.965s","18m"};
	 correctanswer = new ArrayList();
	 useranswers = new ArrayList();
	 correctanswer.Add("1");
	correctanswer.Add("2");
    }

    // Update is called once per frame
    void OnGUI () {

    if(GUI.Button(new Rect(Screen.width-(Screen.width/4),523,130,60),"Assignment"))
            {
                    questionbool1 = true;
            }
            if(questionbool1)
            {
                   windowRect6 = GUI.Window(4, windowRect6, DoMyWindow6, "");
            }

    }
    void DoMyWindow6(int windowID)
    {
    
	GUI.Label(new Rect(10,10,500,100),question[qno].ToString(),newfontStyle);
   if(GUI.Toggle(new Rect(30, 50, 100, 40), toggleTxt1, options1[qno].ToString()))toggleTxt1 = setMeOnly();
   if(GUI.Toggle(new Rect(130, 50, 100, 40), toggleTxt2, options2[qno].ToString()))toggleTxt2 = setMeOnly();
   if(GUI.Toggle(new Rect(250, 50, 100, 40), toggleTxt3, options3[qno].ToString()))toggleTxt3 = setMeOnly();
   if(GUI.Toggle(new Rect(350, 50, 100, 40), toggleTxt4, options4[qno].ToString()))toggleTxt4 = setMeOnly();   
	
    if(GUI.Button(new Rect(450,50,70,30), "NEXT"))
	{
		toggleTxt1=toggleTxt2=toggleTxt3=toggleTxt4= false;
		if(toggleTxt1)
		{
			useranswers.Add("1");
		}
		else if(toggleTxt2)
		{
			useranswers.Add("2");
		}
		else if(toggleTxt3)
		{
			useranswers.Add("3");
		}
		else if(toggleTxt4)
		{
			useranswers.Add("4");
		}
		
		if(qno<1)
		{
			qno++;
	GUI.Label(new Rect(10,10,500,100),question[qno].ToString(),newfontStyle);
	  if(GUI.Toggle(new Rect(30, 50, 100, 40), toggleTxt1, options1[qno].ToString()))
		toggleTxt1 = setMeOnly();	
    if(GUI.Toggle(new Rect(130, 50, 100, 40), toggleTxt2, options2[qno].ToString()))
		toggleTxt2 = setMeOnly();
    if(GUI.Toggle(new Rect(250, 50, 100, 40), toggleTxt3, options3[qno].ToString()))
		toggleTxt3 = setMeOnly();
     if(GUI.Toggle(new Rect(350, 50, 100, 40), toggleTxt4, options4[qno].ToString()))
		toggleTxt4 = setMeOnly();   

// print(useranswers[1]);

		}
	}
    }
    bool setMeOnly(){
    toggleTxt1=toggleTxt2=toggleTxt3=toggleTxt4= false;
    return true;	
    }

}