- Home /
Question by
mfoulks200 · Dec 28, 2013 at 09:28 PM ·
playerprefs
Playerprefs not storing data?
I have a script that should check for a stored username and password, then either send it to be checked, or wait for user input to send off, then change scenes. But for whatever reason, it's not working, can anyone tell why?
var email = "E-Mail";
var password = "Password";
var cam : GameObject; //Assign this in the editor or in Start, find the door
function sendInfo(user, pass){
// Create a form object for sending high score data to the server
var form = new WWWForm();
// Assuming the perl script manages high scores for different games
form.AddField( "email", email );
// The name of the player submitting the scores
form.AddField( "password", password );
var w = WWW("I AM A URL IN THE REAL PROGRAM!", form);
yield w;
if(w.text == "valid"){
PlayerPrefs.SetString("name", email);
PlayerPrefs.SetString("pass", password);
Application.LoadLevel("mainmenu");
}
}
// Create a public variable where we can assign the GUISkin
var customSkin : GUISkin;
function OnGUI () {
if(PlayerPrefs.GetString("name") != null){
if(PlayerPrefs.GetString("pass") != null){
sendInfo(PlayerPrefs.GetString("name"), PlayerPrefs.GetString("pass"));
}
}
GUI.skin = customSkin;
// Make a background box
GUI.Box (Rect (10,(Screen.height*0.5)-125,(Screen.width*0.5)-20,250), "Login");
// Make the text fields
email = GUI.TextField (Rect (60, (Screen.height*0.5)-30, (Screen.width*0.5)-120, 20), email);
password = GUI.PasswordField (Rect (60, (Screen.height*0.5)+5, (Screen.width*0.5)-120, 20), password, "•"[0], 25);
// Make the second button.
if (GUI.Button (Rect (55,(Screen.height*0.5)+40,80,25), "Login")) {
sendInfo(email, password);
}
}
Comment
Have you tried debugging the program using Debug.Log
? Also it seems that you need to have a valid URL for the piece of code you posted to work
Thanks for the tip, and yes the url is an actual url in the real program.
Your answer
Follow this Question
Related Questions
PlayerPrefs Problem crashing with SetBool 2 Answers
How to use PlayerPrefs? 2 Answers
Save level 3 Answers
How to save resources configuration file for unity3d? 0 Answers
Saving Location in Unity 1 Answer