PlayerPrefs, i'm quite confused with it.

Someone gave me the basic code for it. I'm just really confused of how it works. and if I can use it for storing data from Different Users(multiusers)?

I actually need to have a Load game menu, which will ask for the users name, and then load it's level (if the player have played before)

And can i use this as well for displaying the High scores?

When i set it's initial value, how can i change it? and how can i store data/string (name) from a GUI textbox?

I hope someone can teach me about playerPrefs. Please do enlighten me about Using PlayerPrefs.. And sorry for being such a noob.. maybe if i get how PlayerPrefs work, i can be enlightened with my confusions stated above.

UnityAnswers have been a great help to me, Thanks to people who are kind enough to entertain my noob questions.

i tried it, i just want to check whether the entered user was saved.but it doesn't give the right output.

var textFieldString="";
    var check="";

function OnGUI () { textFieldString=GUI.TextField(Rect(25,25,100,30),textFieldString);

`if(GUI.Button(Rect(25,55,100,30),“Save”)) {
saveUser();
}

check=GUI.TextField(Rect(25,95,100,30),check);

if(GUI.Button(Rect(25,120,100,30),“Check”)) {
search();
}

}

function saveUser(){
PlayerPrefs.SetString(“Player Name”, textFieldString);
print(“saved”);
}

function search() {
if(PlayerPrefs.HasKey(check)) {
print(“He played”);
}
else print(“new User”);
}
`

Well, the basic functionality of playerPrefs is pretty straight-forward as it only allows you to set or retrieve an int, float or string or check for a key.

http://unity3d.com/support/documentation/ScriptReference/PlayerPrefs.html

The simplest (and least efficient) way to do what you want is to get the user's name and check against it before loading a new level. So, to save a new username just let him input it and set a playerPrefs entry using it:

var username: String;

function getName(){
        // do your input magic here
        saveLevel();
        }

function saveLevel(){
    PlayerPrefs.SetInt(username+"level", Application.loadedLevel);
    }

To check against a name and load it is equally easy:

var username: String;

function getUsername(){
    //get input
    loadLevel();
}

function loadLevel(){
    if(PlayerPrefs.HasKey(username+"level")){
    Application.LoadLevel(PlayerPrefs.GetInt(username+"level"));
    }   
}

Word of advice: while this simplistic way of doing things will certainly work, it's not really suitable for storing and retrieving a large number of variables. If you have to save more than say highscores and level ints then you should look into ArrayPrefs or even an xml saving/ loading scheme.

Your code above is mostly correct. Here's the fixed up version:

var textFieldString="";
    var check="";

function OnGUI ()  {
    textFieldString=GUI.TextField(Rect(25,25,100,30),textFieldString);

if(GUI.Button(Rect(25,55,100,30),"Save")) {
saveUser();
}

check=GUI.TextField(Rect(25,95,100,30),check);

if(GUI.Button(Rect(25,120,100,30),"Check")) {
search();
}

}

function saveUser(){
PlayerPrefs.SetString("PlayerName", textFieldString);
print("saved");
}

function search() {
 if(PlayerPrefs.HasKey("PlayerName")) { 
    if(PlayerPrefs.GetString("PlayerName") == check){
    print("He played");
 }  
 }
 else print("new User");
 }

Just make sure you also check if the key's value is equal to your "check" input.