Search Unity

  1. All Pro and Enterprise subscribers: find helpful & inspiring creative, tech, and business know-how in the new Unity Success Hub. Sign in to stay up to date.
    Dismiss Notice
  2. Dismiss Notice

Random choose correct and wrong answer and push it to text.

Discussion in 'Scripting' started by JanVermeer, Jan 14, 2021.

  1. JanVermeer

    JanVermeer

    Joined:
    Dec 14, 2020
    Posts:
    5
    Hello!

    My name is Jan and me and some other guys are working on a school project. We are making a kind of Flappy Bird game with two holes in the pipes. But we have a problem. We have an array with correct answer and an array with wrong answers. The arrays are in order by index. So if we choose the correct answer with index 1, we get the corresponding wrong answer with index 1. When we choose those answers, we want them to be written on the screen: in the upper gap of the pipe and in the lower gap of the pipe. But we want it to be random. So that the correct answer is sometimes in the upper gap and in the lower gap. And the same with the wrong answer. When it is chosen, we need to write it on the screen.

    Another problem we get with this is checking if the answer is correct. We now have a function that checks if the bird is flying through the upper gap. When it does, the answer is true. But when it's random, the correct could be in the lower gap aswell.

    We have been trying for over 4 hours now. You guys are the only option know. Could someone help us out?

    Code (CSharp):
    1. // The Arrays (Level Script)
    2. rightAnswers = new List<string>{"Nee", "Cyber beveiligers", "Gebruikersnaam", "Ja", "Een lang wachtwoord", "Persoon blokkeren", "Bericht rapporteren", "Niet delen van gevoelige informatie", "Nee"};
    3.             wrongAnswers = new List<string>{"Ja", "Hackers", "Foto's", "Nee", "Een wachtwoord tekens", "Persoon negeren", "Nare reactie plaatsen", "Zelf gaan pesten", "Ja"};
    4.  
    5. // Checking for answer (Level Script)
    6. for (int i = 0; i < middlePipeList.Count; i++) {
    7.             MiddlePipe middlePipe = middlePipeList[i];
    8.                 if (middlePipe.GetXPosition() > 0 && middlePipe.GetXPosition() < 0.2 && isWaitingAnswer == false) {
    9.                     if(answerDraw() == true) {
    10.                         answer = "Correct";
    11.                     } else {
    12.                         answer = "False";
    13.                     }
    14.                     isWaitingAnswer = true;
    15.                 }
    16.  
    17. // Choosing answers (Level Script)
    18.     public void getRightAnswer(){
    19.         for (int i = 0; i < rightAnswers.Count; i++)
    20.         {
    21.             currentRightAnswer = rightAnswers[randomIndex];
    22.         }
    23.     }
    24.  
    25.     public void getWrongAnswer(){
    26.         for (int i = 0; i < wrongAnswers.Count; i++)
    27.         {
    28.             currentWrongAnswer = wrongAnswers[randomIndex];
    29.         }
    30.     }
    31.  
    32. // Pushing it to the TextWindows Script (Level Script)
    33.     public string GetRightAnswer() {
    34.         return currentRightAnswer;
    35.     }
    36.  
    37.     public string GetWrongAnswer() {
    38.         return currentWrongAnswer;
    39.     }
    40.  
    41. // Writing it to the screen (TextWindow Script)
    42.     private void Bird_Answers(object sender, System.EventArgs e) {
    43.         upperText.text = Level.GetInstance().GetRightAnswer();
    44.  
    45.         lowerText.text = Level.GetInstance().GetWrongAnswer();
    46.  
    47.         Show();
    48.     }
    Thank you in advance! (My english isn't great)
     
  2. JanVermeer

    JanVermeer

    Joined:
    Dec 14, 2020
    Posts:
    5
    We already fixed it! Thanks for reading!
     
unityunity