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 JoshMBeyer · Dec 10, 2014 at 06:38 AM · c#

Before I waist a ton of time... Need help

So I am making a questionnaire. There is 1 question and 4 possible answers. Only one answer is correct however. I will have over 1000 questions and over 4000 answers. If the user chooses the correct answer I don't want that question to be asked again.. If he chooses the wrong answer, then move to the next question randomly but leaving the last question in the pile to be asked again later on. So this is how I am going about it so far. But before I go any further I feel there is a MUCH better way of doing this and will save me some time/efficiency. Any advice is appreciated...

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class QAndA : MonoBehaviour {
     
     public List<string> Questions;
     public List<string> Answers;
     public List<string> IncorrectAnswers;
 
     int question = 0;
     public bool correct;
 
     void Awake()
     {
         //-------------Questions-----------------//
         Questions[0] = "What is 2+2?";
         Questions[1] = "What is 5+5?";
 
 
         //-------------Answers-------------------//
         Answers[0] = "4";
         Answers[1] = "10";
 
         //-------------Incorrect Answers---------//
         IncorrectAnswers[0] = "22";
         IncorrectAnswers[1] = "2";
         IncorrectAnswers[2] = "44";
     }
     
     // Update is called once per frame
     void Update () {
     
     }
     void OnGUI()
     {
         
         switch (question)
         {
             case 0:
                 GUI.Label(new Rect(25, 25, 125, 50), Questions[0]);
                 if(GUI.Button(new Rect(125,25,125,50), Answers[0]))
                 {
                     //Move to the next question, but allow this question to be asked again
                     //At a randomly later time.
                     if (correct) { question = Random.Range(0, Questions.Count); }
                 }
                 if (GUI.Button(new Rect(125, 75, 125, 50), IncorrectAnswers[0]))
                 {
                     //Move to next question randomly and keep this question from being
                     //asked again.
                     Questions.Remove(Questions[0]);
                     question = Random.Range(0, Questions.Count);
                 }
 
                 break;
             case 1:
                 GUI.Label(new Rect(25, 25, 125, 50), Questions[1]);
                 if (GUI.Button(new Rect(125, 25, 125, 50), Answers[1]))
                 {
                     //Move to next question randomly
                     if (correct) { question = Random.Range(0, Questions.Count); }
                 }
                 break;
             case 2:
                 GUI.Label(new Rect(25, 25, 125, 50), Questions[2]);
                 if (GUI.Button(new Rect(125, 25, 125, 50), Answers[2]))
                 {
                     //Move to next question randomly
                     if (correct) { question = Random.Range(0, Questions.Count); }
                 }
                 break;
             case 3:
                 GUI.Label(new Rect(25, 25, 125, 50), Questions[3]);
                 if (GUI.Button(new Rect(125, 25, 125, 50), Answers[3]))
                 {
                     //Move to next question randomly
                     if (correct) { question = Random.Range(0, Questions.Count); }
                 }
                 break;
             case 4:
                 GUI.Label(new Rect(25, 25, 125, 50), Questions[4]);
                 if (GUI.Button(new Rect(125, 25, 125, 50), Answers[4]))
                 {
                     //Move to next question randomly
                     if (correct) { question = Random.Range(0, Questions.Count); }
                 }
                 break;
 
 
         }
     }
 }
 
Comment
Add comment · Show 1
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 JoshMBeyer · Dec 10, 2014 at 06:48 AM 0
Share

I found some advice and this seems more appropriate but my questions still remain the same since there will be 1000+ questions and so on.

 using UnityEngine;
 using System.Collections;
 using System.Collections.Generic;
 
 public class QAndA : $$anonymous$$onoBehaviour 
 {
     void Start()
     {
         var question = new Question();
         question.QuestionText = "What color is snow?";
         question.Answers[0] = "Red";
         question.Answers[1] = "Yellow";
         question.Answers[2] = "White";
         question.Answers[3] = "Green";
         question.CorrectAnswer = 2;
 
         // ... more questions
 
         var listOfQuestions = new List<Question>();
         listOfQuestions.Add(question);
     }
 }
 
 class Question
 {
     public string QuestionText{ get; set; }
     public string AnswerA { get;set; }
     public string AnswerB { get;set; }
     public string AnswerC { get;set; }
     public string AnswerD { get; set; }
 
     public Question()
     {
         Answers = new string[4];
     }
     public string[] Answers { get; set; }
     public int CorrectAnswer { get; set; }
 }
 
 

1 Reply

· Add your reply
  • Sort: 
avatar image
2

Answer by CodeMasterMike · Dec 10, 2014 at 08:55 AM

Writing all questions in a single script file is not a good design. Its hard to maintain and will be extremly slow and hard to debug.

I think the best way to do this, is to create a database with all your questions and answers and other data you need. Then you can alter the text in the database without having to re-build the game later on.

Then have a script to load a random question from the database at runtime whenever a new question should appear.

Good luck!

Comment
Add comment · 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

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

26 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

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Simple Questionnaire Game Logic? 2 Answers

Leaderboard GUISkin? 1 Answer

Raycasting, LineRenderer & Layermasks 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