Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
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
Add comment
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users

0 Replies

· Add your reply
  • Sort: 

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

20 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Beginner : Random gameobject from array 2 Answers

Help with GuiText flickering code. 1 Answer

GUI Menu After every round how do I display a random image? 1 Answer

Randomize an enum list 3 Answers

Problem with random generated objects(intersects objects) 1 Answer


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges