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 Zygia · Oct 03, 2017 at 08:51 AM · unity 5gamequalitysettingsquiz

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

I did this quiz but repeats my questions. How can I change the code because he does not repeat it again? I tried with a check on the old value but repeated the same. Thanks for your help!

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

 public class QuizScript : MonoBehaviour {
     
 
     int oldRange;
     int range;
 
 
     int score;
     float time = 766;
 
     public Text FinalScore;
     public Text ScoreText;
 
     public Texture sfondo;
 
     public Canvas GameCan;
     public Canvas LoseCan;
     public Canvas WinCan;
 
     public Image TimeBar;
 
     public Button Menu;
     public Button Button_1;
     public Button Button_2;
     public Button Button_3;
 
     bool risp1 = false;
     bool risp2 = false;
     bool risp3 = false;
 
     bool timego = true;
     bool timeLose = true;
 
     public Text Question;
     public Text Answ1;
     public Text Answ2;
     public Text Answ3;
 
 
 
 
 
 
     // Use this for initialization
     void Start () {
         
         SelectingRange ();
 
     }
     
     // Update is called once per frame
     void Update () {
         
         if (time >= 0 && timego) {
             time = time - 1;
             TimeBar.rectTransform.sizeDelta = new Vector2 (time - 1, 16);
         } 
         else if (time < 0 && timeLose) {
             timeLose = false;
             Invoke ("HaiPerso", 2);
         }
 
     
         
     }
 
     void SelectingRange(){
         
         time = 766;
         timego = true;
 
         Button_1.interactable = true;
         Button_2.interactable = true;
         Button_3.interactable = true;
         Menu.interactable = true;
 
         Button_1.GetComponent <Image> ().color = Color.blue;
         Button_2.GetComponent <Image> ().color = Color.blue;
         Button_3.GetComponent <Image> ().color = Color.blue;
         Menu.GetComponent<Image> ().color = Color.red;
 
 
     
         oldRange = range;
         range = Random.Range (1, 10);
 
         if (oldRange == range) {
             SelectingRange ();
         } else if(oldRange!= range){
             SpawnQuestion ();
         }
 
      }
 
 
 
 
     void SpawnQuestion(){
         
 
         if (range == 1) {
                 Question.text = "Cos'è una RAM?";
                 Answ1.text = "Un tipo di software";
                 Answ2.text = "Un sistema operativo";
                 Answ3.text = "Una memoria ad accesso casuale";
                 risp3 = true;
             }
 
         if (range == 2) {
                 Question.text = "OS X è un sistema operativo?";
                 Answ1.text = "Windows";
                 Answ2.text = "Mac";
                 Answ3.text = "Linux";
                 risp2 = true;
             }
 
 
         if (range  == 3) {
                 Question.text = "Blender è?";
                 Answ1.text = "Una marca di computer";
                 Answ2.text = "Un software di modellazione 3D";
                 Answ3.text = "Un sistema operativo";
                 risp2 = true;
             }
 
         if (range  == 4) {
                 Question.text = "Cos'è un 'trojan horse'?";
                 Answ1.text = "Uno spyware";
                 Answ2.text = "Un programma che nasconde il suo vero scopo";
                 Answ3.text = "Un worm";
                 risp2 = true;
             }
 
         if (range == 5) {
                 Question.text = "Un Gigabyte corrisponde a?";
                 Answ1.text = "100 Megabyte";
                 Answ2.text = "1024 Megabyte";
                 Answ3.text = "10 Terabyte";
                 risp2 = true;
             }
 
         if (range == 6) {
                 Question.text = "Qual'è l'estensione di un immagine?";
                 Answ1.text = ".txt";
                 Answ2.text = ".xls";
                 Answ3.text = ".jpg";
                 risp3 = true;
             }
 
         if (range == 7) {
                 Question.text = "Un indirizzo email esatto è?";
                 Answ1.text = "www.xxx@gmail.com";
                 Answ2.text = "mariorossigamil.com";
                 Answ3.text = "Nessuno dei precedenti";
                 risp1 = true;
             }
 
         if (range == 8) {
                 Question.text = "Un programma consiste di?";
                 Answ1.text = "Insieme di dati";
                 Answ2.text = "Raccolta di icone";
                 Answ3.text = "Sequenza di istruzioni";
                 risp3 = true;
             }
 
         if (range  == 9) {
                 Question.text = "Con la sigla wwww si indica?";
                 Answ1.text = "Worm Wind Web";
                 Answ2.text = "World Wide Web";
                 Answ3.text = "Work Wilds Web";
                 risp2 = true;
             }
 
         if (range == 10) {
                 Question.text = "Cos'è un hardware?";
                 Answ1.text = "L'unità disco rigido";
                 Answ2.text = "Un programma complesso";
                 Answ3.text = "La parte fisica di un computer";
                 risp3 = true;
             }
 
 
     
     }
 
     public void VaiMenu(){
         GameCan.gameObject.SetActive (false);
         SceneManager.LoadScene (0);
     }
 
     public void ProssimoLivello(){
         GameCan.gameObject.SetActive (false);
         SceneManager.LoadScene (2);
     }
 
 
     public void Button1(){
 
         timego = false;
         DisattivaButton ();
 
         if (risp1 == true) {
             Button_1.GetComponent <Image> ().color = Color.green;
             Invoke ("SelectingRange", 2);
             risp1 = false;
             AddScore ();
         } 
         else {
             Button_1.GetComponent <Image> ().color = Color.red;
             Invoke ("SelectingRange", 2);
         }
     }
 
     public void Button2(){
         timego = false;
         DisattivaButton ();
 
         if (risp2 == true) {
             Button_2.GetComponent <Image> ().color = Color.green;
             Invoke ("SelectingRange", 2);
             risp2 = false;
             AddScore ();
         }
         else {
             Button_2.GetComponent <Image> ().color = Color.red;
             Invoke ("SelectingRange", 2);
         }
     }
 
     public void Button3(){
         timego = false;
         DisattivaButton ();
 
         if (risp3 == true) {
             Button_3.GetComponent <Image> ().color = Color.green;
             Invoke ("SelectingRange", 2);
             risp3 = false;
             AddScore ();
         }
         else {
             Button_3.GetComponent <Image> ().color = Color.red;
             Invoke ("SelectingRange", 2);
         }
     }
 
 
 
     public void Ricomincia(){
         SceneManager.LoadScene (SceneManager.GetActiveScene().name);
     }
 
 
     void AddScore(){
         score = score + 10;
         ScoreText.text = "Score: " + score;
         if (score==100) {
             Invoke ("HaiVinto", 1);
         }
 
     }
 
 
     void HaiPerso(){
         GameCan.gameObject.SetActive (false);
         LoseCan.gameObject.SetActive (true);
         FinalScore.text = "HAI OTTENUTO SOLO: " + score+ " PUNTI";
         
     }
 
     void HaiVinto(){
         GameCan.gameObject.SetActive (false);
         WinCan.gameObject.SetActive (true);
         FinalScore.text = "HAI OTTENUTO: " + score+ " PUNTI";
 
 
     }
 
 
     void DisattivaButton(){
 
         Button_1.interactable = false;
         Button_2.interactable = false;
         Button_3.interactable = false;
     }
 
 
 }
 

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 Positive7 · Oct 03, 2017 at 10:10 AM 0
Share
     private List<int> rangeList = new List<int>();
 
     private int result;
 
     private int RandomNumber
     {
         get
         {
             if (rangeList.Count <= 0) return -1;
             var index = Random.Range(0, rangeList.Count);
             result = rangeList[index];
             rangeList.RemoveAt(index);
             return result;
         }
     }
 
     private void Awake()
     {
         for (var i = 1; i < 11; i++) rangeList.Add(i);
     }

then in your SelectingReange()

     private void SelectingRange()
     {
         //....
         result = RandomNumber;
         SpawnQuestion();
     }

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

210 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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

Problem with upload questions in a quiz game 0 Answers

Why am I able to see exclusive scene elements in game? 0 Answers

Adding a Highscore to game 1 Answer

Someone help me with Physics2D material Bounce? 0 Answers

(DISSOLVED) Error : Failed to build apk. (Unity 2017.2.0f3) 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