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 12:58 AM · arraysarraylist

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.

alt text

alt text

sem-tituloo.png (86.8 kB)
sem-titulooo.png (76.3 kB)
Comment
Add comment · Show 5
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 Oribow · May 08, 2016 at 01:00 AM 0
Share

Why didnt you post your code normal? What should the screenshots add?

avatar image richell Oribow · May 08, 2016 at 01:09 AM 0
Share

Sou novo primeira vez que posto uma perguntas de ajuda, como faço o procedimento, por favor.

avatar image Oribow richell · May 08, 2016 at 01:13 AM 0
Share

I dont speak portugees, I'm from germany. English is the worlds language for a reason.

avatar image TBruce · May 08, 2016 at 01:11 AM 0
Share

When posting code, do not post screen shots people can not help much that way. Please format ALL you code properly and paste the code directly into the body of the question. To do that copy the code to your clipboard and press the "101010" button in the toolbar of the UA text editor. This will format the code so it can be easily read in the forum.

avatar image richell · May 08, 2016 at 01:26 AM 0
Share

using UnityEngine; using UnityEngine.Scene$$anonymous$$anagement; using UnityEngine.UI; using System.Collections;

public class responder : $$anonymous$$onoBehaviour {

 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 = $$anonymous$$athf.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);
     
     Scene$$anonymous$$anager.LoadScene ("notaFinal" + idTema.ToString ());

             
 }

             }

}

1 Reply

· Add your reply
  • Sort: 
avatar image
0

Answer by Oribow · May 08, 2016 at 01:11 AM

You could shuffel your array before hand. Just take you array and randomly swap two elements for a while. So that the elements in the array are already in a random order to begin with. Then just take the first, second, third ... until you reach the end of the array. In that way you wont get duplicats and dont have to remember which elements you already used.

example:

  • {1,2,3,4}

  • swap [2] and [0]

  • swap [3] and [2] ... // as often as you want, with random indcies

  • {4,1,3,2} //result of swaping x times

  • return [0] -> 4

  • return [1] -> 1

  • return [2] -> 3

  • return [3] -> 2

completly random and without duplicats

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

56 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

Related Questions

Keep track of last audio clip played from multiple arrays 1 Answer

Problems with arrays (or how to rewind objects' states) 0 Answers

C# ArrayList Accessing and RemoveAt? 0 Answers

Comparing an ArrayList to the current object in an Arraylist being checked through a forEach Loop? 0 Answers

Why can't I assign a value to the array in the class "Player"? 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