Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 zoukker · Mar 15, 2018 at 09:26 PM · c#pointsquiz

How can I make some questions worth more points?

I did a questionnaire with this script and wanted to make some questions worth more points, can someone help me?

 public Text question;
 public Text answerA;
 public Text answerB;
 public Text infoAnswer;

 public string[] Questions; 
 public string[] alternativeA;
 public string[] alternativeB;
 public string[] corrects;


 private int idQuestion;

 private float correct;
 private float questions;
 private float average;
 private int finalGrade;

 // Use this for initialization
 void Start () 
 {
     
     idQuestion = 0;
     questions = Questions.Length;

     question.text = Questions[idQuestion];
     answerA.text = alternativeA[idQuestion];
     answerB.text = alternativeB[idQuestion];
 
     infoAnswer.text = "Respondendo " + (idQuestion + 1) + " de " + questions.ToString() + " perguntas.";

 }
 
 public void answerr(string alternative)
 {
     if(alternative == "A")
     {
         if (alternativeA[idQuestion] == corrects[idQuestion])    
         {
             correct += 1;

         }
             }
     else if(alternative == "B")
     {
     if (alternativeB[idQuestion] == corrects[idQuestion])    
         {
             correct += 1;

         }    
     }
     

     nexQuestion();

 }

 void nexQuestion()
 {
     idQuestion += 1;
     
     if(idQuestion <= (questions - 1))
     {
     question.text = Questions[idQuestion];
     answerA.text = alternativeA[idQuestion];
     answerB.text = alternativeB[idQuestion];
 
     infoAnswer.text = "Respondendo " + (idQuestion + 1) + " de " + questions.ToString() + " perguntas.";

} else { //nota average = 10 * (correct / questions); //media finalGrade = Mathf.RoundToInt(average); //arredonda a media

     if(finalGrade > PlayerPrefs.GetInt("finalGrade"))

{ PlayerPrefs.SetInt("finalGrade", finalGrade); PlayerPrefs.SetInt("corrects", (int) correct);

} PlayerPrefs.SetInt("finalGradeTemp", finalGrade); PlayerPrefs.SetInt("correctsTemp", (int) correct);

     Application.LoadLevel("evaluation");
 }
 }

}

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
0
Best Answer

Answer by Scribe · Mar 22, 2018 at 09:14 PM

You could follow the same pattern as you are and have

 public int[] questionValue;

which you could then use on lines 40 and 49 as:

 correct += questionValue[idQuestion];

However you might notice that things are getting complicated with so many arrays that all have to be kept in sync. One of the nice things about object oriented programing is that you can encapsulate all these linked pieces of information together in a new class:

 public class Question {
 
     private string answerA;
 
     private string answerB;
 
     private string correctOption;
 
     private int points;
 
     public Question(string answerA, string answerB, string correctOption, int points){
         this.answerA = answerA;
         this.answerB = answerB;
         this.correctOption = correctOption;
         this.points = points;
     }
 
     public string getAlternativeA(){
         return answerA;
     }
 
     public string getAlternativeB(){
         return answerB;
     }
 
     public int scoreOf(string option){
         if(option == correctOption){
             return points;
         }else{
             return 0;
         }
     }
 
 }

This makes it super easy to have all the information you need synchronised up for you and in one place!

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

128 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

Related Questions

[Quiz Game] How to prevent Question asked twice. HELP 1 Answer

How to make questions random, and include from a folder not inside the unity editor 0 Answers

Break the loop when there are no more questions 0 Answers

Collecting items 1 Answer

Quiz on Android crashes, array alternatives ? 2 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