How to pass more than one variable between scenes using playerprefs

Hello,

I have 2 scenes. Scene1 has two texboxes, to display the score and video title. I am storing the text of these two in two different variables. I tried passing on the score to the next scene using playerprefs and it works, same code when I am using with different directory name for the other variable i get the following error in console:
NullReferenceException: Object reference not set to an instance of an object
Scorecontrol.Start () (at Assets/Scripts/Scorecontrol.cs:15)

I am basically passing on the score and the video title along with other details filled in the by the user on the Scene 2 as an email. Is it possible to use playerpref to pass on more than one variable between scenes.I dont have much idea about playerprefs.

here’s my code for saving the values of the variables in scene 1:

PlayerPrefs.SetString(“CurrentScore”, scoreText.text);
PlayerPrefs.SetString(“VideoTitle”, Vidtitle.text);

and this is for getting the values in the Scene2:

scoretext2.text = PlayerPrefs.GetString(“CurrentScore”);
vtitle.text = PlayerPrefs.GetString(“VideoTitle”);

I get the error for the second line.

The easiest and best way I found to do this is to have a object in the scene that doesn’t get destroyed when switching between scenes. Like a GameManager object.

Simply do:

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

Then you can simple add the variables you want to be saved to it.

public int MyInt;
public string MyString";
...

I like this method because you can add entire scripts to the object. So you can have scripts for different things:

PlayerDetails.cs
Achievements.cs
UIController.cs
EnemeySpawner.cs
...

And you are not limited to variables. Common functionality used between scenes can also be used.