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 Pfayzer · Sep 09, 2017 at 12:38 PM · c#quizrandomizing

having a problem with object pooling.

hey guys i am currently making a quiz game for our thesis. we were using the given object pooling at unity tutorial. and some of the features are working but. i am having a problem because i cant show the panel when the button clicked was correct. an the only panel which is showing is the wrongDisplay(Panel). and if I clicked the button on the wrongDisplay(Panel) my program hangs. which supposed to get back at the questionPanel to the other randomly picked question. can somebody help us because there's only two weeks before our final defense. thank you.

here's the code:

Code(CSharp):

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

public class GameController : MonoBehaviour {

 public Text questionDisplayText;
 public Text ScoreDisplayText;
 public Text TimeRemainingDisplayText;
 public Text imageQuestionDisplayText;

 public SimpleObjectPool answerButtonObjectPool;

 public Transform answerButtonParent;

 public GameObject questionDisplay;
 public GameObject WrongDisplay;
 public GameObject timesUpDisplay;
 public GameObject GameOverDisplay;
 public GameObject CorrectDisplay;
 public GameObject pauseButton, pausePanel;



 private DataController dataController;
 private RoundData currentRoundData;
 private QuestionData[] questionPool;

 private bool isRoundActive;

 private float timeRemaining;
 private int questionIndex;    
 private int playerScore;
 private int qNumber = 0;

 private List <GameObject> answerButtonGameObjects = new List<GameObject> ();
 private List <int>  questionIndexesChosen = new List <int>();
 // Use this for initialization

 [SerializeField]
 private float timeBetweenQuestions = 0 ;

 void Start ()
 {
     dataController = FindObjectOfType<DataController> ();
     currentRoundData = dataController.GetCurrentRoundData ();
     questionPool = currentRoundData.questions;
     timeRemaining = currentRoundData.timelimitInSeconds;
     UpdateTimeRemaining ();

     playerScore = 0;
     questionIndex = 0;

     ShowQuestion ();
     QuestionData questionData = questionPool [questionIndex];
     questionDisplayText.text = questionData.questionText;
     pausePanel.SetActive (false);

     health = hearts.Length;
     print (health);

     isRoundActive = true;

 }

 public void OnPause()
 {
     pausePanel.SetActive (true);
     pauseButton.SetActive (false);
     Time.timeScale = 0;



 }
 public void OnUnPause()
 {
     pausePanel.SetActive (false);
     pauseButton.SetActive (true);
     Time.timeScale = 1;


 }
 public void ShowQuestion()
 {
     RemoveAnswerButtons ();

     ChooseQuestion ();
     QuestionData questionData = questionPool [questionIndex];
     questionDisplayText.text = questionData.questionText;
     if (questionDisplayText.text != null) {
         questionDisplay.SetActive (true);
     }
     else
     {
         questionDisplay.SetActive (false);
     
     }
 
     for (int i = 0; i < questionData.answers.Length; i++) 
     {
         GameObject answerButtonGameObject = answerButtonObjectPool.GetObject ();
         answerButtonGameObject.transform.SetParent (answerButtonParent);
         answerButtonGameObjects.Add (answerButtonGameObject);

             AnswerButton answerButton = answerButtonGameObject.GetComponent<AnswerButton> ();
         answerButton.Setup (questionData.answers [i]);
     }
     questionDisplayText.text = questionData.questionText;

 }
 void ChooseQuestion()
 {
     bool questionChosen = false;

     while (questionChosen != true) 
     {
         int random = Random.Range (0,questionPool.Length);

         if (!questionIndexesChosen.Contains (random)) 
         {
             questionIndexesChosen.Add (random);
             questionIndex = random;
             questionChosen = true;
         }
     }
 }
 public void RemoveAnswerButtons()
 {
     while (answerButtonGameObjects.Count > 0)
     {
         answerButtonObjectPool.ReturnObject (answerButtonGameObjects[0]);
         answerButtonGameObjects.RemoveAt (0);
     }
 }

 public void AnswerButtonClicked(bool isCorrect)
 {
     if (isCorrect) {
         
         playerScore += currentRoundData.pointsAddedForCorrectAnswer;
         ScoreDisplayText.text = "Score: " + playerScore.ToString ();

         CorrectDisplay.SetActive (true);
         questionDisplay.SetActive (false);
         StartCoroutine (TimeBetweenQuestions ());


     } 
     if(!isCorrect)
     {
         
         

         WrongDisplay.SetActive (true);
         questionDisplay.SetActive (false);
         StartCoroutine (TimeBetweenQuestions ());

         Time.timeScale = 0;
     }
     if (health == 0) 
     {
         EndRound ();

     }

     if (qNumber + 1 < questionPool.Length)
         
     {
         qNumber++;
         ShowQuestion ();
     }

      else
     {
         EndRound ();
     }

 }


 public void EndRound()
 {
     
     questionDisplay.SetActive (false);
     GameOverDisplay.SetActive (true);
     StartCoroutine (TimeBetweenQuestions ());
     Time.timeScale = 0;

 }

 public void ReturnToQuestionPanel ()
 {
     questionDisplay.SetActive (true);
     ShowQuestion ();
     UpdateTimeRemaining ();
     StartCoroutine (TimeBetweenQuestions ());

 }


  IEnumerator TimeBetweenQuestions()
 {
     yield return new WaitForSeconds (timeBetweenQuestions);
     CorrectDisplay.SetActive (false);
     WrongDisplay.SetActive (false);
     timeRemaining = 15;
     QuestionData questionData = questionPool [questionIndex];
     questionDisplayText.text = questionData.questionText;


 }

 private void UpdateTimeRemaining()
 {
     TimeRemainingDisplayText.text = "Time: " + Mathf.Round (timeRemaining).ToString ();
 }

 // Update is called once per frame
 void Update () {
     if (isRoundActive) 
     {
         timeRemaining -= Time.deltaTime;
         UpdateTimeRemaining ();
     }
     if (timeRemaining <= 0f) 
     {
         qNumber++;
         ShowQuestion ();

         timeRemaining = 15;
         timesUpRound ();
     }
 }
 private void timesUpRound()
 {
     questionDisplay.SetActive (false);
     timesUpDisplay.SetActive (true);
 }

}

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

1 Reply

· Add your reply
  • Sort: 
avatar image
1
Best Answer

Answer by Cuttlas-U · Sep 09, 2017 at 01:25 PM

hi;

well that's a huge code right there ;

did u write it all by your self ?

I mean if so then u should not have some problem like this ;

i cant underestand your question and the relation to the script ;

if u can not solve the problem and runing out of time send to my gmail some screen shot of your project so i can help u savajjad@gmail.com

Comment
Add comment · Show 4 · 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
avatar image Pfayzer · Sep 09, 2017 at 02:19 PM 0
Share

@Cuttlas-U my problem is that when i picked the correct answer, the correct answer panel didn't show up ins$$anonymous$$d the wrong display panel shows. and if I click the button that will return to the question display our program hang up. and didn't return to the question panel that will shows the other randomly pick question.

avatar image Pfayzer · Sep 09, 2017 at 02:20 PM 0
Share

i just edited the given source code from unity site.

avatar image Cuttlas-U Pfayzer · Sep 09, 2017 at 04:12 PM 0
Share

I cant fix the problem only by the code because it may be a problem inside unity editor that's why i need the screen shots of editor :

from these codes i cant see any problems;

avatar image Pfayzer · Sep 14, 2017 at 05:10 AM 0
Share

i just did wait you told me before. im waiting now for your response. Thank you. @Cuttlas-U :)

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

381 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image 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 can I make some questions worth more points? 1 Answer

[Quiz Game] How to prevent Question asked twice. HELP 1 Answer

Break the loop when there are no more questions 0 Answers

Quiz on Android crashes, array alternatives ? 2 Answers

Quiz Game Database 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