Show score on gameover screen?

Hello Unity Answers,

I’m trying to make a simple gameover screen with the score shown to the player.

I have created a new scene and copied everything from the main scene into it and repositioned the score text but the score doesn’t update.

All ideas & suggestions welcome.

using System;
using System.Collections.Generic;
using UnityEngine;
using System.Collections;
using UnityEngine.UI;

public class Question10 : MonoBehaviour {
	
	private Rect windowRect = new Rect (500, 100, 400, 200); //Window size
	public bool question10;
	private int count;
	public Text countText;

	private bool showTimer = true;
	private float Timer = 10f;

	void start()
	{
		count = 0;
		SetCountText ();
	}

	void FixedUpdate(){
		if (showTimer == true) {
			Timer -= Time.deltaTime;
		}
		
		if (Timer <= 0f) {
			showTimer = false;
			Timer = 10f;
			Destroy (this.gameObject);
			Application.LoadLevel (Application.loadedLevel);
		}
	}
	
	void OnGUI()
	{
		windowRect = GUI.Window (0, windowRect, WindowFunction, "Ebola Quiz Island"); //window on screen
	}
	
	
	void WindowFunction (int windowID) 
	{
		// Draw any Controls inside the window here
		GUI.Label(new Rect (30, 25, 400, 50), " How many proven treatments are there for Ebola?"); // Question
		
		if (GUI.Button (new Rect (20, 100, 100, 30), "None")) 
		{
			Destroy (this.gameObject);
			count = count + 10;
			SetCountText ();
			Application.LoadLevel("Gameover");
		}

		if (GUI.Button (new Rect (280, 100, 100, 30), "One"))
		{
			Destroy (this.gameObject);
			Application.LoadLevel("Gameover");
		}

		if (GUI.Button (new Rect (20, 150, 100, 30), "Two"))
		{
			Destroy (this.gameObject);
			Application.LoadLevel("Gameover");
		}

		if (GUI.Button (new Rect (280, 150, 100, 30), "Three"))
		{
			Destroy (this.gameObject);
			Application.LoadLevel("Gameover");
		}

		if (showTimer == true) 
		{
			GUI.Label (new Rect (175, 50, 200, 50), "Timer: " + Timer.ToString ("F0"));
		}


	}

		void SetCountText()
		{
			ValuesHolder.answersCount++;
			countText.text = "Score: " + ValuesHolder.answersCount.ToString();
		}
	
}


using UnityEngine;
using System.Collections;

internal class ValuesHolder
{
	internal static int answersCount = 0;
}

alt text

alt text

**When the player clicks the None the scoreboard scene ( Application.LoadLevel(“Gameover”):wink: will be loaded but the score won’t be updated? :frowning: **

Because You set the text first in line 51 and change the scene in 52 which clears the data. So when the new scene is loaded, you should load the points into your game label. In the GameOver scene you should make a new gameobject (empty) and give it a script. In the script you can call a function, like your SetCountText, but without incrementing the count.

What i don’t get: Why do you have a local count variable, if you use only the static Valuesholder.answersCount?