- Home /
 
 
               Question by 
               Jacques993 · Mar 17, 2014 at 11:53 PM · 
                guirandomarrays  
              
 
              Writing to GUI from an array
Hello, Having an Issue with Arrays, So im trying to call a string from an array, but say, i wanted to have it called from creating a string, instead of showing the string contained in the array, it simply writes for example, if random number is 1 the gui writes Q1[4] instead of "What is the Second Letter in the Alphabet?" I hope the code can help explain it better.
 var theDoor : Transform;
 private var drawGUI = false;
 private var doorIsClosed = true;
 var MenuSkin : GUISkin;
 var number : int;
 var quitMenu : boolean = false;
 var SoundOpen : GameObject;
 
 var questionArray;
 
 // ==================================================================================================
 // CREATING ARRAYS OF QUESTIONS
 // ==================================================================================================
 
 var Q1 = new Array("A","G","Z","B","What is the Second Letter in the Alphabet?","The Correct Answer Is Actually B!"); 
 var Q2 = new Array("Triangle","Circle","Square","Hexagon","What is the name of 4 sided shape?","The Correct Answer Is Actually a Square!"); 
 var Q3 = new Array("Dog","Giraffe","Cat","Mouse","Name a Tall Animal?","The Correct Answer Is Actually a Giraffe!"); 
 var Q4 = new Array("London","Coventry","Birmingham","Manchester","Which is the capital of England?","The Correct Answer Is Actually London!"); 
 
  
 // ==================================================================================================
 // ENTERING THE COLLIDER
 // ==================================================================================================
 
 function OnTriggerEnter (theCollider : Collider) 
 {
     if (theCollider.tag == "Player")
     {
         number = Random.Range(1,5);
         drawGUI = true;    
         pauseMouse();
         Screen.showCursor = true;
     }
 }
 
 function Update () 
 {
     if(Input.GetKeyDown(KeyCode.Escape)) 
     {
     quitMenu = !quitMenu;
     }
 }
 
 // ==================================================================================================
 // DRAW GUI QUESTIONS TO OPEN DOOR
 // ==================================================================================================
 
 function OnGUI ()
 {
     questionArray = ('Q'+number+'[4]');
     
     if(quitMenu == true) 
     {
         GUI.skin = MenuSkin;    
         GUI.color = Color.green;
         
         GUI.Box (Rect (Screen.width*0.5-51, 200, 402, 22), " " + (questionArray)); 
 
         if(GUI.Button(Rect(0,Screen.height - 860, 350,40),"debug menu"))     
         {
 
             Application.Quit();
         }
  
 
              
               Comment
              
 
               
              Your answer