title: Displaying score in another scene on Unity
body: <p>In the game I am creating a 'Game Over' scene which loads once the player loses the game. During the game, the score is counted by the player's position on the screen and increases as the player's y-axis position increases. </p>
  
  <p>I used this code to display the score on the scene the game was actually played:</p>
  
  
  
  <pre class="lang-c# prettyprint-override"><code>using UnityEngine;
  using UnityEngine.UI;
  
  public class PlayerScore : MonoBehaviour 
  {
  
      public Transform player;
      public Text scoreText; 
  
      // Update is called once per frame
      void Update() 
      {
          scoreText.text = player.position.y.ToString("0"); 
      }
  }
  </code></pre>
  
  <p>I tried to use the same coding to display the final score of the player on the 'Game Over' screen. The problem I faced was that I was <strong>not able to identify the player on the 'Game Over' scene as the player was not an object or sprite on that scene</strong>.</p>
  
  <p>Is there an easy way to reference the player sprite from the previous scene into the final ('Game Over') scene so I can use it to determine the final score?</p>
  
  <p>This is the script I tried with a game object of the 'EndScene' within the playing scene:</p>
  
  <pre class="lang-c# prettyprint-override"><code>using System.Collections;
  using System.Collections.Generic;
  using UnityEngine;
  using UnityEngine.UI;
  using UnityEngine.SceneManagement;
  
  public class EndMenu: MonoBehaviour 
  {
  
      public Text scoreText;
      public Transform player;
      public static bool GameEnds = false;
      public GameObject endMenuUI;
  
      void OnCollisionEnter2D(Collision2D exampleCol) 
      {
          if(exampleCol.collider.tag == "Obstacle")
          {
              endMenuUI.SetActive(true);
              Time.timeScale = 0.0001f;
              GameEnds = true;
          }
      }
  
      public void Retry()
      {
          SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex - 1);
      }
  
      public void BackToMenu()
      {
          SceneManager.LoadScene("Menu");
      }
  
      public void Quit()
      {
          Debug.Log("Quitting game...");
          Application.Quit();
      }
  
      // Update is called once per frame
      void Update()
      {
          scoreText.text = player.position.y.ToString("0");
      }
  }
  </code></pre>