Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
12 Jun 22 - 14 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 /
  • Help Room /
avatar image
0
Question by dino231990 · May 15, 2019 at 10:52 PM · gameunityeditorquiz

Stuck with unity quiz game logic

I am trying to creeate a quiz where the user is shown 8 or 6 Images along side a larger image panel the objective is for the user to guess the correct rule for sequence and click the box corresponding to the answer.

  1. Currently each game object for the image has a renderer attached for the image to change when a new question is loaded and i have a reference to the panel to display a larger picture as the question I can currently change the buttons and the image using values stored from an array for each

  2. The bit i am struggling with currently is how change the question randomly when a correct answer is chosen. I currently have set up classes with each values to change the images of everything to a new question but i cannot figure out how to loop through these and setup a random set of images for the questions

    example class for a single question: private void practice1() {

          //Qbtns = sprite renderer array-quesBtn is a list of images
     for the buttons/ or answers 
             Qbtns[0].sprite = quesBtn[0];
             Qbtns[1].sprite = quesBtn[1];
             Qbtns[2].sprite = quesBtn[2];
             Qbtns[3].sprite = quesBtn[3];
             Qbtns[4].sprite = quesBtn[4];
             Qbtns[5].sprite = quesBtn[5];
             Qbtns[6].sprite = quesBtn[6];
             Qbtns[7].sprite = quesBtn[7];
     
             panel.GetComponent<Image>().sprite =
     queS[0];
     
     }
    
    
    
    
  3. I was thinking something like a switch statement to go through these but i am stuck with logic of how to loop thorugh these

      switch
             (Questions1[Questions1.Count])
                     {
                         case 1:
                             practice1();
                             break;
                         case 2:
                             practice2();
                             break;
                         case 3:
                             test1();
                             break;
     
    
    

I attempted to make this as clear as possible but i understand its a bit long winded, thanks to anyone who takes the time to read/answer! :D

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by tormentoarmagedoom · May 16, 2019 at 08:05 AM

Hello dino.

If you pretend to find a random element in an array, you will need to use Random.Range()

And then, if pretend to no repeat one element, to recieve always a new one, you should have a "availability array". I mean, have a boolean array, so each question stores in this array when is used.

So you should have some logic like this:

 bool [] QuationsUsed = new bool[number of questions]
 int number = random.range
 
 while ( QuationsUsed[number] = true)
 {
 number = random.range
 }

At this point, numbner will be only a non-taken question/number. So now, lets use it.

You chose Questions[number] , and set its bool as true to prevent beeig selected again

 QuationsUsed [number] = true;

Thats all you need!

Bye!

Comment
Add comment · Show 1 · Share
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
avatar image dino231990 · May 16, 2019 at 01:42 PM 0
Share

thanks for this answer , i will try it out and let you know

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

173 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 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 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 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 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 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 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 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 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

How do I modify my code to not repeat the questions? 0 Answers

question about a script 0 Answers

How do I edit assets?,How do I change Assets 0 Answers

Admob Interstitial Ads not showing after published in playstore 1 Answer

Answers from JSON file appears in Random order problem 0 Answers


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