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”);
}
`
thanks for the answer.made it a little clearer. but still got some confusions. I tried it, posted the code above. i tried saving a user and checking whether it has been saved.i didn't get the right output :( what's wrong with it?
– anon94770209You were pretty close. I've fixed it for you above.
– anon53712941oh yeah!thanks!i think i'm getting how it works.. when i enter another player name, will the old one be retrieved? where do it saves the new one? thanks for the great help!!!
– anon94770209You should check the link I provided. Unity stores playerPrefs in various locations depending on your pc/ device. When you enter another playername it will overwrite this one. That's why my example saves to a variable playerprefs key ("username"). Any one key can only hold one value unless you use array prefs (so playerName can only hold azzogat f.e). Setting another name to playerName will overwrite azzogat.
– anon53712941aww..i see..i guess i have to learn array prefs as well.. because i need to have to hold atleast 30 players in same computers. Is it far from playerprefs?Will it be hard to search for the name when i use that?thanks really!!hope you won't get tired in answering me.take care!
– anon94770209