Hey,
I’m very much new to Unity and not too familiar with how things work. I wouldn’t even say that I’m an intermediate at programming altogether, please don’t be too harsh on me. I’m currently working on creating my first small project Top-Down 2D game. I’ve handled the basics like movement, following camera, a small basic map however I’ve encountered a first logic problem which I’ve been stuck on for some time now, namely, I’m trying to implement a “quiz system”, sort of like a multiple choice quiz system. I wrote a data structure class to store the questions and answers.
I wrote a script that handles activating the canvas(since it’s initially disabled) when the player interacts with the 2D quiz game object sort of like QuizPanel. There is a method(ActivateQuiz) called here which is part of another script(QuizManager) for activating the actual quiz(populating questions and answers into the data structure etc.).
There’s a second script QuizManager like I mentioned, that handles populating the quiz. This script is tied as a component of the canvas itself. The logic works that in the Start method of QuizManager the questions and answers get added into the data structure(quizList) that I mentioned. The method for activating the quiz(ActivateQuiz), that I mentioned previously, which gets invoked by the previous script(QuizPanel), is inside of this script(QuizManager).
This is where the issue happens.
In the ActivateQuiz method I first check whether all questions have been answered previously. This logic serves the sole purpose so that after all questions have been answered correctly at least once the quiz has a screen where it says something like “congratulations you’ve completed this quiz, move on to the next quiz panel”.
Afterwards comes the logic for taking the questions from quizList data structure and filling the Toggles, question text etc.
To get back on track.
I have an index for each question and I do a check here. A pretty basic if statement like:
if QuestionIndex >= QuizList.count
return
… here’s the problem
this if is always triggered, therefor the return happens.
The questions in the Start method weren’t populated into the QuizList before this check happens hence why it “seems” as if all questions were already answered.
To me this looks like a synchronization issue.
How do I know this? I set breakpoints and attached a debugger to unity. I pressed play and did the interacting with the 2D Game Object. The script for activating the canvas itself is setup so that it if the player is in range of the 2D Quiz panel game object and a button on the keyboard was pressed the ActivateQuiz method of QuizManager is called.
I’d really appreciate any help so please if you think you can, don’t hesitate to write a reply.