PlayerPrefs clashing with TextField?

Hello all,

I’ve been trying to use PlayerPrefs (only since I weren’t able to get unity to create cookies, dunno why) and I have been able to save and get info from PlayerPrefs.
My problem starts when I try to change the text string I have imported from the PlayerPrefs at Awake()/Start().
For some reason the TextField showing the text string imported, won’t let me modify the field now. No key stroke works.

Any ideas?

Thanks in advance.

following is the code I used:

if(!PlayerPrefs.HasKey("Username") && createCookie){ //check if the user already exists and if he asked to be remembered
    PlayerPrefs.SetString("Username",Username);
    PlayerPrefs.SetString("Password",Password);
    PlayerPrefs.SetString("User",Name+" "+Surname); //saving the full name with which the user logged in
}else if(!createCookie){ //if he doesn't ask to be remembered, i run a "delete all" just to make sure. I have no other place where i use playerprefs so its ok.
    PlayerPrefs.DeleteAll();
}

now the part where i’m saving the data

if(Username=="" && PlayerPrefs.HasKey("Username")){
    Username=PlayerPrefs.GetString("Username");
    Password=PlayerPrefs.GetString("Password");
}

*note: i consider myself a fairly intelligent human being and quite the internet savvy, but i STILL don’t understand how the heck this code format thing works…

edit:
I’m adding the code for the GUI, as requested by Bunny83, where you can see that I actually DID write it as you suggested.

GUI.Label(Rect(20,30,80,20),"Username:");
Username = GUI.TextField(Rect(90,30,100,20),Username);
GUI.Label(Rect(20,60,80,20),"Password:");
Password = GUI.PasswordField(Rect(90,60,100,20),Password,"*"[0],16);
createCookie = GUI.Toggle(Rect(20,80,100,20),createCookie,"Remember Me");

:D just select (highlight) the code and press the "101 010"-button. This will indent every line by 4 spaces and insert empty lines around the code block. This is how UA recognises code. You can also use html tags <pre></pre> or something like that. UA will automatically convert your 4-indent code block to a <pre> code block after some time. Keep in mind that there's a real-time-preview below your edit field, so you can see how it looks like.

I got it that far, it's just that when i select the code and click the code button, it writes "enter code here" in the beginning of the text and ignores the fact that i have selected anything.

2 Answers

2

Ehmm :D if you have problems with the TextField in Unity, you should post that code. I'm pretty sure you use the TextField like this:

GUILayout.TextField(Username);

This function returns the edited text, so you have to do it this way:

Username = GUILayout.TextField(Username);

edit

ps. works the same for GUI.TextField.

This is my code i used for the GUI. As you can see i have already done as you said. GUI.Label(Rect(20,30,80,20),"Username:"); Username = GUI.TextField(Rect(90,30,100,20),Username); GUI.Label(Rect(20,60,80,20),"Password:"); Password = GUI.PasswordField(Rect(90,60,100,20),Password,"*"[0],16); createCookie=GUI.Toggle(Rect(20,80,100,20),createCookie,"Remember Me");

The annoying part is that on the editor if works, while exporting it as a webplayer, gives me that problem.

Stupid question, stupid solution:

Put the variable load part in Start(){} and gui in OnGUI(){} of course.

Happy Kwanza everybody!