- Home /
How to combine two percentage scores from different scenes?
I'm working on a quiz game that score is in percent. I am trying to combine two scenes scores into one percent but cannot get them to add correctly. The first scene uses this code for scoring:
// Score percent
public void SetScore()
{
if (FundamentalsTwototalQuestions > 0)
{
FundamentalsTwoscorePerc = (FundamentalsTwoTotalCorrect / FundamentalsTwototalQuestions) * 100; FundamentalsscoreObj.GetComponent().text = "Score: " + Mathf.Round(FundamentalsTwoscorePerc) + " %";
}
The second scene uses this code for scoring:
// Score percent
public void SetScore()
{
CombineQuestions = (FundamentalstotalQuestions + AnsweredQuestions);
CombineScore = (Newscore + FundamentalsscorePerc) / 2;
FundamentalsscoreObj.GetComponent<Text>().text = "Score: " + Mathf.Round(CombineScore) + " %";
if (FundamentalstotalQuestions > 0)
{
FundamentalsscorePerc = (FundamentalstotalCorrect / CombineQuestions) * 100;
}
Answer by davidcox70 · Aug 06, 2018 at 10:30 PM
Calculate the percentage score of the second scene in the same way that you caluclated it in the first scene;
(numberCorrectAnswers/numberOfQuestions)*100;
Then add the two percentage numbers together and half the result. That will give you the combined percentage.
davidcox70 thanks for the reply. How do you suggest I code it because I tried: CombineScore = (Newscore + FundamentalsscorePerc) / 2;
If NewScore is a percentage, and FundamentalscorePerc is a percentage, then it should work. What's not working? Your code snippet doesn't show how you are getting NewScore, so check that those maths are correct. Also check that you are properly storing FundamentalscorePerc from the previous scene and it isn't returning 0.