- Home /
How do I get this code to run specified amount of times
What I am trying to do is make a math question generator, once an object is disabled. I want a new equation to appear each time the user inputs the correct answer. I want it to run a specified amount of time, but I can only either get it to run once, or unlimited
This is what I have come up with so far
I know I did not word this that well, but im basically asking, how do I get the question generator to appear a set period of time, with new equation once a specific object is destroyed.
Let's find out what exactly you want :
1)How many GameObject
s with the Text
component and with the tag "equations" exist in your scene?
2)Can you share the your Disable()
method
Disable() is the sd.png located on the bottom, both images are for the other parts of the script
only 1 component is tagged equation which is for the text box
the text box shows the equation needed to be solved
ex 1+1 would show in the text box
the object doesn't get destroyed, just disabled.
The code works for the question generator to appear, but you can only answer 1 problem then the generator disappears and you go back to the other part of the game, I need it to have the user enter for example like 3 questions then the generator can disappear and continue the game
Answer by IamAnewUser · May 15, 2019 at 04:43 PM
I'm guessing you want three questions displayed (each one after the previous has been answered correctly) and not to generate three times a question in a single frame, right?
In this case you have to
*create int correctAnswered = 0
at the start of your script
*remove the for
loop entirely from QuestionAnswerInput()
and replace it with this instead
//amountOfQuestionsYouWantToBeDisplayed could be for example 3 for three questions
correctAnswered ++;
if(correctAnswered < amountOfQuestionsYouWantToBeDisplayed){
QuestionGen();
}else{
correctAnswered = 0;
//do what you want to end the questions here
}
Hope this helps
Yes it worked THAN$$anonymous$$S so much, just needed to add correctAnswered++; before the the QuestionGen(); and that solution worked
I really appreciate the help, was trying to figure this out for like 2 hours <3
You got to put it before the if
(like in the answer) or it will display one less question