How to make a variable to not reset when a scene changes?

Hello,
Ok so this question may sound stupid but i’m new to unity and i’m implementing my second game where the game levels is on different scene and when i complete the first level and move on to the second level, the score should not reset and and should increment on the previous level score…Can anyone explain to me how this can be done please. Thanks

SohailBukhari is right. Playerprefs is how you would save the variables for each scene. took me a while to understand it myself.

but in my case I have all my variables that i want saved throughout each scene in one script that I can call the save function throughout my code with getters and setters.

public class GameManager : MonoBehaviour 
{

//this code lets me call my gamemanager script from other scripts
	private static GameManager instance;
	public static GameManager Instance{get{return instance;}}

//these are my variables that I have i want saved throughout the game
	public int currentSkinIndex = 0;
	public int currency = 0;
	public int skinAvailability = 1;
	public int loadCount = 0;
        public bool disabledAds = false;

In the Awake method ,In my code, I have a string set that if my player has the 1st skin there was a previous session and need to check all the variables I list to update their values if they need to be updated. yours can been whatever.

//if player has had a previous session the you list your variables you would like to update next. make sure instead of PlayerPrefs.HasInt you put .GetInt after each variable. then in the () after .GetInt place your string name that you wish to save in your registry.

	private void Awake()
	{
		instance = this;

		/////code for determining saves and not saved games////

		if (PlayerPrefs.HasKey ("CurrentSkin"))
               { 
			currentSkinIndex = PlayerPrefs.GetInt("CurrentSkin");
			currency = PlayerPrefs.GetInt("Currency");
			skinAvailability = PlayerPrefs.GetInt("SkinAvailability");

          //fun fact: these last two are my way of saving how many times my player dies/restarts the game I want between each ad.
			loadCount = PlayerPrefs.GetInt ("Count");
			disabledAds = (PlayerPrefs.GetInt("noAds") != 0);
		   } else 

//after you enter all of these you call your save function that is below.
		{
			Save();
		}
	}

in your save function you use PlayerPrefs.SetInt to save each variable to your registry. here inside the () you have to put the string name you want in the registry and your variable.

public void Save()
	{
		PlayerPrefs.SetInt("CurrentSkin", currentSkinIndex);
		PlayerPrefs.SetInt("Currency" , currency);
		PlayerPrefs.SetInt ("SkinAvailability", skinAvailability);
		PlayerPrefs.SetInt ("Count", loadCount);
		PlayerPrefs.SetInt("noAds", (disabledAds ? 1 : 0));
	}

And then whenever I want to call my save function like at the end of a level or when the player dies where ever I am at in the script I just and a simple line like…

GameManager.instance.save();

And that calls the save function into the registry to save the values of each variable I put in my GameManager.

And thats it. I hope this wasn’t too confusing for you and I hope it helps you with your game. Good luck programming!

You should use Playerprefs for score.

See the documentation of PlayerPrefs https://docs.unity3d.com/ScriptReference/PlayerPrefs.html