- Home /
all 10 questions , after random question , it come out 9 questions.
I want to try , if I don't touch the button of final question ,EndGame() will work . how can I do? thx
public void AnsButtonClick(bool isCorrect)
{
isClickButton = true;
if(questionPools.Count > 0)
{
ShowQuestion();
}
else
{
EndGame();
}
}
void Update()
{
if(isRoundActive)
{
timeRemaining -= Time.deltaTime;
UpdateTimeRemain();
if(isClickButton)
{
timeRemaining = 5.0f;
}
if(timeRemaining <= 0 )
{
timeRemaining = 5.0f;
ShowQuestion();
/*if (questionPools.Count <= 0 )
{
EndGame();
}*/ //if the code put here , it can come out tenth question, but after time pass and I don't touch the button , EndGame(); can't work and It will say Index was out of range.
}
/*if (questionPools.Count <= 0 )
{
EndGame();
}*/ //If the code put here , when ninth question end ,EndGame(); start work. My count have 10 questions , only 9 questions come out , why?
}
isClickButton = false;
}
Hi there, it would be useful to see the code sections where you modify the questionPools
list. If questions are removed from list once you answer them, you should only need to check if there are none left in AnsButtonClick()
. The EndGame()
checks inside Update loop may be extraneous / happening too frequently. Also, you can just use if (questionPools.Count == 0)
ins$$anonymous$$d of <= 0
, since .Count will never return a negative value.
Hi @ryanreptoid , I found the problem in the Update() .
So , I fix the code and it's can work . thank you for help.
void Update()
{
if(isRoundActive)
{
timeRemaining -= Time.deltaTime;
UpdateTimeRemain();
if(isClickButton)
{
timeRemaining = 5.0f;
}
if(timeRemaining <= 0 )
{
timeRemaining = 5.0f;
if (questionPools.Count > 0 )
{
ShowQuestion();
}
else
{
EndGame();
}
}
}
isClickButton = false;
}
Your answer
Follow this Question
Related Questions
Randomizing numbers on a list. 4 Answers
A node in a childnode? 1 Answer
Random instantiation endlessly? 1 Answer