void UpdateTimer()
{
timerValue -= Time.deltaTime;
if(isAnsweringQuestion)
{
if (timerValue <= 0)
{
isAnsweringQuestion = false;
timerValue = timeToShowCorrectAnswer;
}
}
else
{
if(timerValue <= 0)
{
isAnsweringQuestion = true;
timerValue = timeToCompleteQuestion;
}
}
Hello!!! I’m currently doing the quiz master portion of the Unity 2d course. And tried to figure out the challenge in “part 61. Simple Timer”. When I failed time and time again with this I watched the solution (seen above) and now i’m wondering why we are using if-statements within if-statements? Why do you do it that way instead of like this?:
if(isAnsweringQuestion && timerValue <= 0)
{
isAnsweringQuestion = false;
timerValue = timeToShowCorrectAnswer;
}
else if (timerValue <= 0)
{
isAnsweringQuestion = true;
timerValue = timeToCompleteQuestion;
}
Is there any merit to one over the other, except that the one I made is easier to look at?? Something like “If we want to do this and that in the future it is better to have a if-statement inside another if-statement” or “If you do it this way the code is more optimized for performance.”.
Regards // Gruvbyggare