Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 14 Next capture
2021 2022 2023
2 captures
13 Jun 22 - 14 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 AmISquidward · Jun 22, 2021 at 11:48 AM · scripting problemscripting beginnervisual studiobugsquiz

Finishing up my 2D quiz game [Last Problem]

I have problem with my true false quiz game. I'm still new at using unity. Here is the link to my problem that I write on forum because its more clear and easy to understand there. https://forum.unity.com/threads/finishing-up-my-2d-quiz-game.1129834/


But here is the summary:

  1. I try to make the game end and show congratulation screen IF the player answer 20 question correctly but the unity keep freezing when I answer the 19th question. Even if I make the index to 10 or 5 for example, it freeze in 9th or 4th question. So basically it always freeze on the last 2 question.

  2. I try to make the game end and show game over screen IF the player answer 1 question wrong. And the game over screen will also tell the last score that player currently have. But the problem is I still don't know how to make it happen.


Here is the scripts on my game that I think relevant to my game:


  • Result Script : The core of the game. To manage in game button, score, transition for next question, etc


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

    public class Result : MonoBehaviour { public Questions questions; public GameObject correctSprite; public GameObject incorrectSprite; public GameObject completeLevelUI;

       public GameOverScreen gameOverScreen;
     
         public Scores scores;
     
         public Button trueButton;
         public Button falseButton;
     
         public UnityEvent onNextQuestion;
     
         void Start()
         {
             correctSprite.SetActive(false);
             incorrectSprite.SetActive(false);
         }
     
         public void ShowResults(bool answer)
         {
             correctSprite.SetActive(questions.questionsList[questions.currentQuestion].isTrue == answer);
             incorrectSprite.SetActive(questions.questionsList[questions.currentQuestion].isTrue != answer);
     
             if (questions.questionsList[questions.currentQuestion].isTrue == answer)
                 scores.AddScore();
             else
                 scores.DeductScore();
     
             trueButton.interactable = false;
             falseButton.interactable = false;
     
             StartCoroutine(ShowResult());
         }
     
         private IEnumerator ShowResult()
         {
             yield return new WaitForSeconds(1.0f);
     
             correctSprite.SetActive(false);
             incorrectSprite.SetActive(false);
     
             trueButton.interactable = true;
             falseButton.interactable = true;
     
             onNextQuestion.Invoke();
         }
        
         public void CompleteLevel ()
         {
             completeLevelUI.SetActive(true);
         }
     }
    
    
    

  • Questions Script: To store question


    using System.Collections; using System.Collections.Generic; using UnityEngine;

    [CreateAssetMenu] [System.Serializable]

    public class Questions : ScriptableObject { [System.Serializable]

       public class QuestionData
         {
             public string question = string.Empty;
             public bool isTrue = false;
             public bool questioned = false;
         }
     
         public int currentQuestion = 0;
         public List<QuestionData> questionsList;
     
         public void AddQuestion()
         {
             questionsList.Add(new QuestionData());
         }
     }
    
    
    

  • QuestionsData Script : To manage question in game.


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

    public class QuestionsData : MonoBehaviour { public Questions questions; [SerializeField] private Text _questionText;

       void Start()
         {
             AskQuestion();
         }
     
         public void AskQuestion()
         {
             var randomIndex = 0;
             do
             {
                 randomIndex = UnityEngine.Random.Range(0, 20);
             } 
             while (questions.questionsList[randomIndex].questioned == true);
     
             questions.currentQuestion = randomIndex;
             questions.questionsList[questions.currentQuestion].questioned = true;
             _questionText.text = questions.questionsList[questions.currentQuestion].question;
         }
     
         public void ClearQuestion()
         {
             foreach (var question in questions.questionsList)
             {
                question.questioned = false;
             }
         }
     }
     
    
    
    

  • Scores Script : For in game scoring


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

    public class Scores : MonoBehaviour { public Text scoreText; private int _currentScore;

       void Start()
         {
             _currentScore = 0;
             scoreText.text = _currentScore.ToString();
         }
     
         public void AddScore()
         {
             _currentScore += 10;
             scoreText.text = _currentScore.ToString();
         }
        
         public void DeductScore()
         {
             _currentScore = _currentScore > 0 ? _currentScore - 10 : 0;
         }
     }
     
    
    
    

  • Congratulation script : To create congratulation screen when the player answer 20 question correctly.


    using System.Collections; using System.Collections.Generic; using UnityEngine;

    public class Congratulation : MonoBehaviour { public Result result;

           void onTriggerEnter()
             {
                 result.CompleteLevel();
             }
     }
     
    
    
    

  • GameOverScreen Script : To make the game over when the player answer the question wrong and show the current score.


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

    public class GameOverScreen : MonoBehaviour { public Text pointsText;

       public void Setup(int Scores)
         {
             gameObject.SetActive(true);
             pointsText.text = Scores.ToString();
         }
     }
     
    
    
    

Please help. I'm still very new at this. This is actually the first game I ever made.

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

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

How to display random questions without repeating the previous? 2 Answers

unity visual studios not working properly 0 Answers

How to make a thrown object land on a certain point e.g a thrown spear landing on its tip 0 Answers

Can you tag words themselves in unity besides game objects? 0 Answers

Movement script preventing gravity 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