Saving travelled distance as a score

Hello im making a runner game and I am at the part where I have set up my score system. For my game the score will be the distance you have travelled. I want to know how could I save the distance I travelled in my level scene and show it in my game over scene. Here is the full script that Im using to get my travelled distance.

using UnityEngine;
using System.Collections;
 
public class Runner : MonoBehaviour {
 
    public static float distanceTraveled;
 
    public float acceleration;
    public Vector3 boostVelocity, jumpVelocity;
    public float gameOverY;
 
    private bool touchingPlatform;
	
	private static int boosts;
 
    void Update () {
       if(Input.GetButtonDown("Jump")){
			if(touchingPlatform){
         rigidbody.AddForce(jumpVelocity, ForceMode.VelocityChange);
         touchingPlatform = false;
				}
			else if(boosts > 0){
				rigidbody.AddForce(boostVelocity, ForceMode.VelocityChange);
				boosts -= 1;
				GUIManager.SetBoosts(boosts);
			}
       }
       distanceTraveled = transform.localPosition.x;
		GUIManager.SetDistance(distanceTraveled);
 
       if(transform.localPosition.y < gameOverY)
	StartCoroutine("DelayedLevelLoad");
	}
				
			IEnumerator DelayedLevelLoad(){
          yield return new WaitForSeconds(1);
          Application.LoadLevel("GameOver");
         }
			
 
    void FixedUpdate () {
       if(touchingPlatform){
         rigidbody.AddForce(acceleration, 0f, 0f, ForceMode.Acceleration);
       }
    }
 
    void OnCollisionEnter () {
       touchingPlatform = true;
    }
 
    void OnCollisionExit () {
       touchingPlatform = false;
    }
	
	private void GameStart () {
		boosts = 0;
		GUIManager.SetBoosts(boosts);
		distanceTraveled = 0f;
		GUIManager.SetDistance(distanceTraveled);
		
	}
	
	public static void AddBoost(){
		boosts += 1;
		GUIManager.SetBoosts(boosts);
	}
}

Right now the only way of knowing my score is just that I can see it in the top part of my screen, but when I die I cant check anywhere what my score was. So any ideas on how I could do this?

Three methods:

  • Use Object.DontDestroyOnLoad() so a particular object that has a script attached containing the information you need is not destoryed on the new scene load.
  • Use PlayerPrefs to store the information. This store is permanent (i.e. it remains after the game is quit), so if you want each game to start at zero, you will need to set it to zero at the beginning of hte game.
  • Use a Singleton. There is an example on this page showing how to track a score.