Don't lose variable data when reloading a level - c#

Hi, In my game when I used Respawn() I want it to obviously respawn the player, however I want it to save the amount of lives and score the player has when the level is reloaded. When the player does die it reloads the level but the live remain on 3.

public int lives = 3;

void Respawn()
	{
		lives -= 1;
		DontDestroyOnLoad (gameObject);
		Livestext (); //ignore
		Application.LoadLevel(Application.loadedLevel);
	}

As you can see I tried DontDestroyOnLoad but I still had the same results…

Thanks in advance.

Use PlayerPrefs

You can store permanent data using PlayerPrefs. When the game first starts, call

PlayerPrefs.SetInt("lives", 3);

And on death call

 PlayerPrefs.SetInt("lives", PlayerPrefs.GetInt("lives")-1);

Try using it this way:

void Awake() {
     DontDestroyOnLoad(transform.gameObject);
}