Can playerPrefs tutorial be inserted into Unity learn website?

Hello team,

This is directed to the unity team since my title is about the learn website. Unless other members of the forum can help insert examples, I hope the unity team can reply to this.

It appears that the internet cannot show a proper, useful or complete example. Please take note that whilst members have used 2 files like in the previous post, I want my variable to be independent. That means I want step by step how to insert them in a game. Can your team work on this? I hope all examples, including premium ones are still provided for free so everyone can improve as a whole. Whilst I do have a previous project that I obtained from paid tutorials, I still have to spend time puzzling out how it works. I want one where proper explanation is given like the existing tutorials I used which will always be valued.

The PlayerPrefs class is very straightforward. You set and get float, int, and string values. The values are identified by strings.

PlayerPrefs.SetFloat("Float", 0.3f);
PlayerPrefs.SetInt("Int", 6);
PlayerPrefs.SetString("String", "Hello");

float foo = PlayerPrefs.GetFloat("Float");
int bar = PlayerPrefs.GetInt("Int");
string baz = PlayerPrefs.GetString("String");

I am unclear what “independent” means, based on your description here and from the prior discussion. There is nothing stopping you from just writing and reading PlayerPref values anywhere in your program.

It is prudent to do this in a centralized place so that you have a clear idea of what is causing the values to change. Hence the “extra files”.

1 Like

Oh my goodness, this is hilarious. You are awesome. Thank you.

Here’s an example of simple persistent loading/saving values using PlayerPrefs:

https://gist.github.com/kurtdekker/01da815d2dfd336a925ae38019c3a163

Useful for a relatively small number of simple values.

1 Like

What does this even mean? How are your variables to be “independent”? Independent of what? And do you really need to know how to put variables in your scripts? Surely you are beyond needing that level of help.

Why should they have to work on any sort of tutorials for this? There is this great thing called the documentation where it clearly shows how to use all of the methods for PlayerPrefs in little example snippets of code. You shouldn’t need more than that to put the loading and saving of variables into your scripts.

2 Likes