Why isn't PlayerPrefs.GetInt() in unity not working?

I am working on a project where I want to make a Scoreboard scene but before I started, I wanted to know and understand what PlayerPrefs.GetInt() was. After reading the api, I did a test to see if it works. I went to the registry editor on windows, went to my project and added a new string value called Player Name, and I attached an int value of 20, just for the test. I created an int variable called number and I made it public so I can see what value is attached to it when I ran unity. Here is my script:

public int number;

void Start() {
    number = PlayerPrefs.GetInt ("Player Name", 10);
}

And for some kind of reason, the only number attached to number is 10. Why? I would really appreciate your help. If you have any questions, you can simply ask.

Upvotes: 0

Views: 2009

Answers (1)

Programmer
Programmer

Reputation: 125325

I went to the registry editor on windows, went to my project and added a new string value called Player Name

That's just wrong. You don't set PlayerPrefs from the Registry. You use the PlayerPrefs.SetInt to save it and PlayerPrefs.GetInt to read it.

Save:

PlayerPrefs.SetInt("Player Name", 20);
PlayerPrefs.Save();

Read:

int number = PlayerPrefs.GetInt("Player Name", 20);

Upvotes: 2

Related Questions