Search Unity

How to keep TEXT information when reloading a level?

Discussion in 'Scripting' started by shorex1991, Dec 25, 2017.

  1. shorex1991

    shorex1991

    Joined:
    Dec 21, 2017
    Posts:
    17
    Hi! first of all, i am newbie with this... i would like to know how can i keep an text showing up, after i picked up an item, on the screen even when i reset the level of the game - it's a rogue like game.

    i did everything i could, but my knowledge is almost 0 here...

    the game is almost complete, just need to set this (make the text allways show up) to finish.

    the text "win( ,1,2,3,4,5,6)Text" which i want to make appear, will pop up after the score from the "count" triggers it, and will be active always after the levels resets

    this is the code im using:

    Code (CSharp):
    1. using UnityEngine;
    2. using System.Collections;
    3. using UnityEngine.UI;    //Allows us to use UI.
    4. using UnityEngine.SceneManagement;
    5.  
    6. namespace Completed
    7. {
    8.     //Player inherits from MovingObject, our base class for objects that can move, Enemy also inherits from this.
    9.     public class Player : MovingObject
    10.     {
    11.         public float restartLevelDelay = 1f;        //Delay time in seconds to restart level.
    12.         public int pointsPerFood = 10;                //Number of points to add to player food points when picking up a food object.
    13.         public int pointsPerSoda = 20;                //Number of points to add to player food points when picking up a soda object.
    14.         public int pointsPerEsfera = 1;
    15.         public int wallDamage = 1;                    //How much damage a player does to a wall when chopping it.
    16.         public Text foodText;                        //UI Text to display current player food total.
    17.         public Text countText;
    18.         public Text winText;
    19.         public Text win1Text;
    20.         public Text win2Text;
    21.         public Text win3Text;
    22.         public Text win4Text;
    23.         public Text win5Text;
    24.         public Text win6Text;
    25.         public Text win7Text;
    26.         public AudioClip moveSound1;                //1 of 2 Audio clips to play when player moves.
    27.         public AudioClip moveSound2;                //2 of 2 Audio clips to play when player moves.
    28.         public AudioClip eatSound1;                    //1 of 2 Audio clips to play when player collects a food object.
    29.         public AudioClip eatSound2;                    //2 of 2 Audio clips to play when player collects a food object.
    30.         public AudioClip drinkSound1;                //1 of 2 Audio clips to play when player collects a soda object.
    31.         public AudioClip drinkSound2;                //2 of 2 Audio clips to play when player collects a soda object.
    32.         public AudioClip gameOverSound;                //Audio clip to play when player dies.
    33.         public AudioClip pokeSound;
    34.  
    35.         [SerializeField] Image Image1;
    36.  
    37.  
    38.  
    39.  
    40.         [SerializeField] Image showImage;
    41.         int maxEsfera = 7;
    42.  
    43.         private int image1;
    44.         private int count;
    45.         private Animator animator;                    //Used to store a reference to the Player's animator component.
    46.         private int food;                           //Used to store player food points total during level.
    47. #if UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_IPHONE
    48.         private Vector2 touchOrigin = -Vector2.one;    //Used to store location of screen touch origin for mobile controls.
    49. #endif
    50.        
    51.        
    52.         //Start overrides the Start function of MovingObject
    53.         protected override void Start ()
    54.         {
    55.             //Get a component reference to the Player's animator component
    56.             animator = GetComponent<Animator>();
    57.            
    58.             //Get the current food point total stored in GameManager.instance between levels.
    59.             food = GameManager.instance.playerFoodPoints;
    60.            
    61.             //Set the foodText to reflect the current player food total.
    62.             foodText.text = "Food: " + food;
    63.            
    64.             //Call the Start function of the MovingObject base class.
    65.             base.Start ();
    66.  
    67.             count = GameManager.instance.playerEsferaPoints;
    68.             countText.text = "Esferas: " + count;
    69.  
    70.  
    71.        
    72.  
    73.  
    74.             SetCountText ();
    75.  
    76.  
    77.  
    78.            
    79.             winText.text = "";
    80.             win1Text.text = "";
    81.             win2Text.text = "";
    82.             win3Text.text = "";
    83.             win4Text.text = "";
    84.             win5Text.text = "";
    85.             win6Text.text = "";
    86.             win7Text.text = "";
    87.  
    88.  
    89.  
    90.             Image1.enabled = false;
    91.             showImage.enabled = false;
    92.         }
    93.  
    94.        
    95.         //This function is called when the behaviour becomes disabled or inactive.
    96.         private void OnDisable ()
    97.         {
    98.             //When Player object is disabled, store the current local food total in the GameManager so it can be re-loaded in next level.
    99.             GameManager.instance.playerFoodPoints = food;
    100.             GameManager.instance.playerEsferaPoints = count;
    101.  
    102.  
    103.         }
    104.        
    105.        
    106.         private void Update ()
    107.         {
    108.             //If it's not the player's turn, exit the function.
    109.             if(!GameManager.instance.playersTurn) return;
    110.            
    111.             int horizontal = 0;      //Used to store the horizontal move direction.
    112.             int vertical = 0;        //Used to store the vertical move direction.
    113.            
    114.             //Check if we are running either in the Unity editor or in a standalone build.
    115. #if UNITY_STANDALONE || UNITY_WEBPLAYER
    116.            
    117.             //Get input from the input manager, round it to an integer and store in horizontal to set x axis move direction
    118.             horizontal = (int) (Input.GetAxisRaw ("Horizontal"));
    119.            
    120.             //Get input from the input manager, round it to an integer and store in vertical to set y axis move direction
    121.             vertical = (int) (Input.GetAxisRaw ("Vertical"));
    122.            
    123.             //Check if moving horizontally, if so set vertical to zero.
    124.             if(horizontal != 0)
    125.             {
    126.                 vertical = 0;
    127.             }
    128.             //Check if we are running on iOS, Android, Windows Phone 8 or Unity iPhone
    129. #elif UNITY_IOS || UNITY_ANDROID || UNITY_WP8 || UNITY_IPHONE
    130.            
    131.             //Check if Input has registered more than zero touches
    132.             if (Input.touchCount > 0)
    133.             {
    134.                 //Store the first touch detected.
    135.                 Touch myTouch = Input.touches[0];
    136.                
    137.                 //Check if the phase of that touch equals Began
    138.                 if (myTouch.phase == TouchPhase.Began)
    139.                 {
    140.                     //If so, set touchOrigin to the position of that touch
    141.                     touchOrigin = myTouch.position;
    142.                 }
    143.                
    144.                 //If the touch phase is not Began, and instead is equal to Ended and the x of touchOrigin is greater or equal to zero:
    145.                 else if (myTouch.phase == TouchPhase.Ended && touchOrigin.x >= 0)
    146.                 {
    147.                     //Set touchEnd to equal the position of this touch
    148.                     Vector2 touchEnd = myTouch.position;
    149.                    
    150.                     //Calculate the difference between the beginning and end of the touch on the x axis.
    151.                     float x = touchEnd.x - touchOrigin.x;
    152.                    
    153.                     //Calculate the difference between the beginning and end of the touch on the y axis.
    154.                     float y = touchEnd.y - touchOrigin.y;
    155.                    
    156.                     //Set touchOrigin.x to -1 so that our else if statement will evaluate false and not repeat immediately.
    157.                     touchOrigin.x = -1;
    158.                    
    159.                     //Check if the difference along the x axis is greater than the difference along the y axis.
    160.                     if (Mathf.Abs(x) > Mathf.Abs(y))
    161.                         //If x is greater than zero, set horizontal to 1, otherwise set it to -1
    162.                         horizontal = x > 0 ? 1 : -1;
    163.                     else
    164.                         //If y is greater than zero, set horizontal to 1, otherwise set it to -1
    165.                         vertical = y > 0 ? 1 : -1;
    166.                 }
    167.             }
    168.            
    169. #endif //End of mobile platform dependendent compilation section started above with #elif
    170.             //Check if we have a non-zero value for horizontal or vertical
    171.             if(horizontal != 0 || vertical != 0)
    172.             {
    173.                 //Call AttemptMove passing in the generic parameter Wall, since that is what Player may interact with if they encounter one (by attacking it)
    174.                 //Pass in horizontal and vertical as parameters to specify the direction to move Player in.
    175.                 AttemptMove<Wall> (horizontal, vertical);
    176.             }
    177.         }
    178.        
    179.         //AttemptMove overrides the AttemptMove function in the base class MovingObject
    180.         //AttemptMove takes a generic parameter T which for Player will be of the type Wall, it also takes integers for x and y direction to move in.
    181.         protected override void AttemptMove <T> (int xDir, int yDir)
    182.         {
    183.             //Every time player moves, subtract from food points total.
    184.             food--;
    185.            
    186.             //Update food text display to reflect current score.
    187.        
    188.  
    189.             foodText.text = "Food: " + food;
    190.            
    191.             //Call the AttemptMove method of the base class, passing in the component T (in this case Wall) and x and y direction to move.
    192.             base.AttemptMove <T> (xDir, yDir);
    193.            
    194.             //Hit allows us to reference the result of the Linecast done in Move.
    195.             RaycastHit2D hit;
    196.            
    197.             //If Move returns true, meaning Player was able to move into an empty space.
    198.             if (Move (xDir, yDir, out hit))
    199.             {
    200.                 //Call RandomizeSfx of SoundManager to play the move sound, passing in two audio clips to choose from.
    201.                 SoundManager.instance.RandomizeSfx (moveSound1, moveSound2);
    202.             }
    203.            
    204.             //Since the player has moved and lost food points, check if the game has ended.
    205.             CheckIfGameOver ();
    206.            
    207.             //Set the playersTurn boolean of GameManager to false now that players turn is over.
    208.             GameManager.instance.playersTurn = false;
    209.         }
    210.        
    211.        
    212.         //OnCantMove overrides the abstract function OnCantMove in MovingObject.
    213.         //It takes a generic parameter T which in the case of Player is a Wall which the player can attack and destroy.
    214.         protected override void OnCantMove <T> (T component)
    215.         {
    216.             //Set hitWall to equal the component passed in as a parameter.
    217.             Wall hitWall = component as Wall;
    218.            
    219.             //Call the DamageWall function of the Wall we are hitting.
    220.             hitWall.DamageWall (wallDamage);
    221.            
    222.             //Set the attack trigger of the player's animation controller in order to play the player's attack animation.
    223.             animator.SetTrigger ("playerChop");
    224.         }
    225.        
    226.        
    227.         //OnTriggerEnter2D is sent when another object enters a trigger collider attached to this object (2D physics only).
    228.         private void OnTriggerEnter2D (Collider2D other)
    229.         {
    230.  
    231.             //Check if the tag of the trigger collided with is Exit.
    232.             if(other.tag == "Exit")
    233.             {
    234.                 //Invoke the Restart function to start the next level with a delay of restartLevelDelay (default 1 second).
    235.                 Invoke ("Restart", restartLevelDelay);
    236.                
    237.                 //Disable the player object since level is over.
    238.                 enabled = false;
    239.             }
    240.            
    241.             //Check if the tag of the trigger collided with is Food.
    242.             else if(other.tag == "Food")
    243.             {
    244.                 //Add pointsPerFood to the players current food total.
    245.                 food += pointsPerFood;
    246.                
    247.                 //Update foodText to represent current total and notify player that they gained points
    248.                 foodText.text = "+" + pointsPerFood + " Food: " + food;
    249.                
    250.                 //Call the RandomizeSfx function of SoundManager and pass in two eating sounds to choose between to play the eating sound effect.
    251.                 SoundManager.instance.RandomizeSfx (eatSound1, eatSound2);
    252.                
    253.                 //Disable the food object the player collided with.
    254.                 other.gameObject.SetActive (false);
    255.             }
    256.            
    257.             //Check if the tag of the trigger collided with is Soda.
    258.             else if(other.tag == "Soda")
    259.             {
    260.                 //Add pointsPerSoda to players food points total
    261.                 food += pointsPerSoda;
    262.                
    263.                 //Update foodText to represent current total and notify player that they gained points
    264.                 foodText.text = "+" + pointsPerSoda + " Food: " + food;
    265.                
    266.                 //Call the RandomizeSfx function of SoundManager and pass in two drinking sounds to choose between to play the drinking sound effect.
    267.                 SoundManager.instance.RandomizeSfx (drinkSound1, drinkSound2);
    268.                
    269.                 //Disable the soda object the player collided with.
    270.                 other.gameObject.SetActive (false);
    271.             }
    272.  
    273.             else if(other.tag == "Esfera")
    274.             {
    275.                
    276.                 count += pointsPerEsfera;
    277.  
    278.                 if (other.gameObject.CompareTag ("Esfera")) {
    279.                 other.gameObject.SetActive (false);
    280.                
    281.  
    282.                 SetCountText ();
    283.  
    284.                 CheckPickUps ();
    285.             }
    286.  
    287.         }
    288.         }
    289.  
    290.         void CheckPickUps ()
    291.         {
    292.         if (count == maxEsfera)
    293.             {
    294.                 showImage.enabled = true;
    295.             }
    296.         }
    297.        
    298.  
    299.         void SetCountText ()
    300.         {
    301.             countText.text = "Esferas: " + count.ToString ();
    302.             if (count == 1) {
    303.                 winText.text = "Maíra...";
    304.                 win1Text.text= "Maíra...";
    305.             }
    306.             if (count == 2){
    307.                 winText.text = "Sei que o ano foi complicado, mas...";
    308.                 win2Text.text= "Sei que o ano foi complicado, mas...";
    309.             }
    310.             if (count == 3){
    311.                 winText.text = "Obrigado por compartilhar comigo";
    312.                 win3Text.text= "Obrigado por compartilhar comigo";
    313.             }
    314.             if (count == 4){
    315.                 winText.text = "Teu tempo e sentimentos.";
    316.                 win4Text.text= "Teu tempo e sentimentos.";
    317.             }
    318.             if (count == 5){
    319.                 winText.text = "Tu é uma pessoa incrível!";
    320.                 win5Text.text= "Tu é uma pessoa incrível!";
    321.             }
    322.             if (count == 6){
    323.                 winText.text = "E por isso eu...";
    324.                 win6Text.text= "E por isso eu...";
    325.             }
    326.             if (count == 7){
    327.                 winText.text = "Desejo que você seja feliz!";
    328.                 win7Text.text= "Desejo que você seja feliz!";
    329.  
    330.                 SoundManager.instance.PlaySingle (pokeSound);
    331.             }
    332.             if (count == 1) {
    333.                 Image1.enabled = true;
    334.             }
    335.         }
    336.        
    337.  
    338.         //Restart reloads the scene when called.
    339.         private void Restart ()
    340.         {
    341.             //Load the last scene loaded, in this case Main, the only scene in the game. And we load it in "Single" mode so it replace the existing one
    342.             //and not load all the scene object in the current scene.
    343.             SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex, LoadSceneMode.Single);
    344.         }
    345.        
    346.        
    347.         //LoseFood is called when an enemy attacks the player.
    348.         //It takes a parameter loss which specifies how many points to lose.
    349.         public void LoseFood (int loss)
    350.         {
    351.             //Set the trigger for the player animator to transition to the playerHit animation.
    352.             animator.SetTrigger ("playerHit");
    353.            
    354.             //Subtract lost food points from the players total.
    355.             food -= loss;
    356.            
    357.             //Update the food display with the new total.
    358.             foodText.text = "-"+ loss + " Food: " + food;
    359.            
    360.             //Check to see if game has ended.
    361.             CheckIfGameOver ();
    362.         }
    363.        
    364.        
    365.         //CheckIfGameOver checks if the player is out of food points and if so, ends the game.
    366.         private void CheckIfGameOver ()
    367.         {
    368.             //Check if food point total is less than or equal to zero.
    369.             if (food <= 0)
    370.             {
    371.                 //Call the PlaySingle function of SoundManager and pass it the gameOverSound as the audio clip to play.
    372.                 SoundManager.instance.PlaySingle (gameOverSound);
    373.                
    374.                 //Stop the background music.
    375.                 SoundManager.instance.musicSource.Stop();
    376.                
    377.                 //Call the GameOver function of GameManager.
    378.                 GameManager.instance.GameOver ();
    379.             }
    380.         }
    381.     }
    382. }
     
  2. OneCept-Games

    OneCept-Games

    Joined:
    Oct 21, 2016
    Posts:
    5
    You can solve this in two ways;
    1: Save your text strings using the PlayerPrefs object, and reload them when you restart your level (load's the scene)
    2: Make your GameManager a Singleton, and call DontDestroyOnLoad(GameObject) in the initialization of your object.

    See this tutorial about saving and loading your high score, it might give you what you need:
    https://unity3d.com/learn/tutorials/topics/scripting/high-score-playerprefs

    Good luck with you game
     
  3. shorex1991

    shorex1991

    Joined:
    Dec 21, 2017
    Posts:
    17
    i dont understand this language, im new... could you help me? im doind the roguelike 2D tutorial, i'vce creater all game, but now i want to change a bit.

    i tryed somethings, but didnt work

    here is the Manager script:

    Code (CSharp):
    1. using UnityEngine;
    2. using UnityEngine.SceneManagement;
    3. using System.Collections;
    4.  
    5. namespace Completed
    6. {
    7.     using System.Collections.Generic;        //Allows us to use Lists.
    8.     using UnityEngine.UI;                    //Allows us to use UI.
    9.    
    10.     public class GameManager : MonoBehaviour
    11.     {
    12.         public float levelStartDelay = 2f;                        //Time to wait before starting level, in seconds.
    13.         public float turnDelay = 0.1f;                            //Delay between each Player turn.
    14.         public int playerFoodPoints = 100;                        //Starting value for Player food points.
    15.         public int playerEsferaPoints = 0;
    16.         public int playerwin1Text;
    17.         public int playerwin2Text;
    18.         public int playerwin3Text;
    19.         public int playerwin4Text;
    20.         public int playerwin5Text;
    21.         public int playerwin6Text;
    22.         public int playerwin7Text;
    23.         public int Image1;
    24.    
    25.  
    26.         public static GameManager instance = null;                //Static instance of GameManager which allows it to be accessed by any other script.
    27.         [HideInInspector] public bool playersTurn = true;        //Boolean to check if it's players turn, hidden in inspector but public.
    28.        
    29.  
    30.         private Text levelText;                                    //Text to display current level number.
    31.         private GameObject levelImage;                            //Image to block out level as levels are being set up, background for levelText.
    32.         private BoardManager boardScript;                        //Store a reference to our BoardManager which will set up the level.
    33.         private int level = 1;                                    //Current level number, expressed in game as "Day 1".
    34.         private List<Enemy> enemies;                            //List of all Enemy units, used to issue them move commands.
    35.         private bool enemiesMoving;                                //Boolean to check if enemies are moving.
    36.         private bool doingSetup = true;                            //Boolean to check if we're setting up board, prevent Player from moving during setup.
    37.        
    38.        
    39.        
    40.         //Awake is always called before any Start functions
    41.         void Awake()
    42.         {
    43.             //Check if instance already exists
    44.             if (instance == null)
    45.  
    46.                 //if not, set instance to this
    47.                 instance = this;
    48.  
    49.             //If instance already exists and it's not this:
    50.             else if (instance != this)
    51.  
    52.                 //Then destroy this. This enforces our singleton pattern, meaning there can only ever be one instance of a GameManager.
    53.                 Destroy(gameObject);  
    54.            
    55.             //Sets this to not be destroyed when reloading scene
    56.             DontDestroyOnLoad(gameObject);
    57.  
    58.            
    59.             //Assign enemies to a new List of Enemy objects.
    60.             enemies = new List<Enemy>();
    61.            
    62.             //Get a component reference to the attached BoardManager script
    63.             boardScript = GetComponent<BoardManager>();
    64.            
    65.             //Call the InitGame function to initialize the first level
    66.             InitGame();
    67.  
    68.  
    69.         }
    70.  
    71.         //this is called only once, and the paramter tell it to be called only after the scene was loaded
    72.         //(otherwise, our Scene Load callback would be called the very first load, and we don't want that)
    73.         [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
    74.         static public void CallbackInitialization()
    75.         {
    76.             //register the callback to be called everytime the scene is loaded
    77.             SceneManager.sceneLoaded += OnSceneLoaded;
    78.         }
    79.  
    80.         //This is called each time a scene is loaded.
    81.         static private void OnSceneLoaded(Scene arg0, LoadSceneMode arg1)
    82.         {
    83.             instance.level++;
    84.             instance.InitGame();
    85.         }
    86.  
    87.        
    88.         //Initializes the game for each level.
    89.         void InitGame()
    90.         {
    91.             //While doingSetup is true the player can't move, prevent player from moving while title card is up.
    92.             doingSetup = true;
    93.            
    94.             //Get a reference to our image LevelImage by finding it by name.
    95.  
    96.  
    97.  
    98.             levelImage = GameObject.Find("LevelImage");
    99.            
    100.             //Get a reference to our text LevelText's text component by finding it by name and calling GetComponent.
    101.             levelText = GameObject.Find("LevelText").GetComponent<Text>();
    102.            
    103.             //Set the text of levelText to the string "Day" and append the current level number.
    104.             levelText.text = "Dia " + level;
    105.            
    106.             //Set levelImage to active blocking player's view of the game board during setup.
    107.             levelImage.SetActive(true);
    108.            
    109.             //Call the HideLevelImage function with a delay in seconds of levelStartDelay.
    110.             Invoke("HideLevelImage", levelStartDelay);
    111.            
    112.             //Clear any Enemy objects in our List to prepare for next level.
    113.             enemies.Clear();
    114.            
    115.             //Call the SetupScene function of the BoardManager script, pass it current level number.
    116.             boardScript.SetupScene(level);
    117.            
    118.         }
    119.        
    120.        
    121.         //Hides black image used between levels
    122.         void HideLevelImage()
    123.         {
    124.             //Disable the levelImage gameObject.
    125.             levelImage.SetActive(false);
    126.            
    127.             //Set doingSetup to false allowing player to move again.
    128.             doingSetup = false;
    129.         }
    130.        
    131.         //Update is called every frame.
    132.         void Update()
    133.         {
    134.             //Check that playersTurn or enemiesMoving or doingSetup are not currently true.
    135.             if(playersTurn || enemiesMoving || doingSetup)
    136.                
    137.                 //If any of these are true, return and do not start MoveEnemies.
    138.                 return;
    139.            
    140.             //Start moving enemies.
    141.             StartCoroutine (MoveEnemies ());
    142.         }
    143.        
    144.         //Call this to add the passed in Enemy to the List of Enemy objects.
    145.         public void AddEnemyToList(Enemy script)
    146.         {
    147.             //Add Enemy to List enemies.
    148.             enemies.Add(script);
    149.         }
    150.        
    151.        
    152.         //GameOver is called when the player reaches 0 food points
    153.         public void GameOver()
    154.         {
    155.  
    156.  
    157.             //Set levelText to display number of levels passed and game over message
    158.             levelText.text = "Goku aguentou " + level + " dias.";
    159.            
    160.             //Enable black background image gameObject.
    161.             levelImage.SetActive(true);
    162.            
    163.             //Disable this GameManager.
    164.             enabled = false;
    165.         }
    166.        
    167.         //Coroutine to move enemies in sequence.
    168.         IEnumerator MoveEnemies()
    169.         {
    170.             //While enemiesMoving is true player is unable to move.
    171.             enemiesMoving = true;
    172.            
    173.             //Wait for turnDelay seconds, defaults to .1 (100 ms).
    174.             yield return new WaitForSeconds(turnDelay);
    175.            
    176.             //If there are no enemies spawned (IE in first level):
    177.             if (enemies.Count == 0)
    178.             {
    179.                 //Wait for turnDelay seconds between moves, replaces delay caused by enemies moving when there are none.
    180.                 yield return new WaitForSeconds(turnDelay);
    181.             }
    182.            
    183.             //Loop through List of Enemy objects.
    184.             for (int i = 0; i < enemies.Count; i++)
    185.             {
    186.                 //Call the MoveEnemy function of Enemy at index i in the enemies List.
    187.                 enemies[i].MoveEnemy ();
    188.                
    189.                 //Wait for Enemy's moveTime before moving next Enemy,
    190.                 yield return new WaitForSeconds(enemies[i].moveTime);
    191.             }
    192.             //Once Enemies are done moving, set playersTurn to true so player can move.
    193.             playersTurn = true;
    194.            
    195.             //Enemies are done moving, set enemiesMoving to false.
    196.             enemiesMoving = false;
    197.         }
    198.     }
    199. }
     
  4. methos5k

    methos5k

    Joined:
    Aug 3, 2015
    Posts:
    8,712
    You should search the internet a little bit for PlayerPrefs example and/or DontDestroyOnLoad.

    PlayerPrefs is a dictionary of key value pairs, where you can save/load information. As said above, you could save your data, and when the scene changes, you load the data and display it , again.

    With DontDestroyOnLoad, that tells the Unity engine to keep your game object between scenes. It won't be destroyed automatically, so if you have some data (manager) or even UI object, you can keep it between scenes. You have to choose what seems best for you. The best way to know what fits for you is to learn about them a little bit :)

    Hope that helps.
     
    OneCept-Games likes this.