The Score Keeper

I have a couple of questions regarding score keeping.

  1. If I wanted to score with a value of 0% to start, and with every correct answer receive 10% from a 10 question quiz, what code would I follow?

  2. When my timer runs out during timetoanswerquestion, and no answer is selected, it is false but my score does not update per each question. My final score is accurate however. Did I miss something?

SHAMAN

For the first question you can simply replace the questionsSeen variable with a reference to the number of questions in the List<QuestionSO> from the Quiz script. For that you’d need to tell ScoreKeeper the total number of questions, and since Quiz already contains a reference to ScoreKeeper it would be simplest to send the value by setting up a public method in Scorekeeper such as:

int questionCount;

public void SetQuestionCount(int count)
{
    questionCount = count;
}

Then change the CalculateScore method to use that value:

    public int CalculateScore()
    {
        return Mathf.RoundToInt(correctAnswers / (float)questionCount * 100);
    }

If you have ten questions, every correct answer will award 10%

In Quiz you’ll have to make sure to send the value by using the public method, probably in Start:

void Start()
{
    scoreKeeper.SetQuestionCount(questions.Count);
}

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms