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 richell · May 08, 2016 at 02:23 AM · arrayarraylist

I'm doing a quiz game I need help. How can I make an array (called random questions) to exit and return to the same are not repeated.

using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; using System.Collections;

public class responder : MonoBehaviour {

 public int idTema;

 public Text pergunta;
 public Text respostaA;
 public Text respostaB;
 public Text respostaC;
 public Text respostaD;
 public Text infoRespostas;

 public string[] perguntas;  // armazena todas as perguntas.
 public string[] alternativaA; // armazena todas as perguntasA.
 public string[] alternativaB; // armazena todas as perguntasB.
 public string[] alternativaC; // armazena todas as perguntasC.
 public string[] alternativaD; // armazena todas as perguntasD.
 public string[] corretas; // armazena todas as alternativas corretas.

 private int idPergunta;

 private float acertos;
 private float questoes;
 private float media;
 private int notaFinal;

 // Use this for initialization
 void Start () {
     idTema = PlayerPrefs.GetInt ("idTema");
     idPergunta = 0;
     questoes = perguntas.Length;

     pergunta.text = perguntas[idPergunta];
     respostaA.text = alternativaA[idPergunta];
     respostaB.text = alternativaB[idPergunta];
     respostaC.text = alternativaC[idPergunta];
     respostaD.text = alternativaD[idPergunta];

     infoRespostas.text = " Respondendo " + (idPergunta + 1).ToString () + " de " + questoes.ToString () + " perguntas! ";
 }
 
 public void resposta(string alternativa)
 {
     if(alternativa == "A")    
     {
         if (alternativaA[idPergunta] == corretas [idPergunta])

         {
                 acertos += 1;
             }
     }
     else if(alternativa == "B") 
     {
         if (alternativaB [idPergunta] == corretas [idPergunta])

                 {
                     acertos += 1;
                 }
       }
     else if(alternativa == "C") 
     {
         if (alternativaC [idPergunta] == corretas [idPergunta]) 

                     {
                         acertos += 1;
                     }
                             
                 }
     else if(alternativa == "D") 
             {
         if (alternativaD [idPergunta] == corretas [idPergunta]) 

                     {
                             acertos += 1;
                         }
                     }    

                      proximaPergunta();
                 
                 }


                 void proximaPergunta()
 {
     idPergunta += 1;

     if (idPergunta <= (questoes - 1)) 
     {            

         pergunta.text = perguntas [idPergunta];
         respostaA.text = alternativaA [idPergunta];
         respostaB.text = alternativaB [idPergunta];
         respostaC.text = alternativaC [idPergunta];
         respostaD.text = alternativaD [idPergunta];
                 
         infoRespostas.text = " respondendo " + (idPergunta + 1).ToString () + " de " + questoes.ToString () + " perguntas! ";
     } 
     else 
     
     {

         media = 10 * (acertos / questoes);
         notaFinal = Mathf.RoundToInt (media);

         if (notaFinal > PlayerPrefs.GetInt ("notaFinal" + idTema.ToString ())) {

             PlayerPrefs.SetInt ("notaFinal" + idTema.ToString (), notaFinal);
             PlayerPrefs.SetInt ("acertos" + idTema.ToString (), (int)acertos);
         }

         PlayerPrefs.SetInt ("notaFinalTemp" + idTema.ToString (), notaFinal);
         PlayerPrefs.SetInt ("acertosTemp" + idTema.ToString (), (int)acertos);
     
     SceneManager.LoadScene ("notaFinal" + idTema.ToString ());

             
 }

             }

}

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

57 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

Related Questions

Is it possible to have 2 references in an array? 1 Answer

Is it possible to store one dimension of a 2d array into a 1d array? 0 Answers

How to edit Properties of a ScriptableObject asset, specificly arrays/lists 0 Answers

How to get text from array or in bool? 1 Answer

How to compare a position of an object within an array 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