Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 13 Next capture
2021 2022 2023
1 capture
13 Jun 22 - 13 Jun 22
sparklines
Close Help
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
  • Asset Store
  • Get Unity

UNITY ACCOUNT

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account
  • Blog
  • Forums
  • Answers
  • Evangelists
  • User Groups
  • Beta Program
  • Advisory Panel

Navigation

  • Home
  • Products
  • Solutions
  • Made with Unity
  • Learning
  • Support & Services
  • Community
    • Blog
    • Forums
    • Answers
    • Evangelists
    • User Groups
    • Beta Program
    • Advisory Panel

Unity account

You need a Unity Account to shop in the Online and Asset Stores, participate in the Unity Community and manage your license portfolio. Login Create account

Language

  • Chinese
  • Spanish
  • Japanese
  • Korean
  • Portuguese
  • Ask a question
  • Spaces
    • Default
    • Help Room
    • META
    • Moderators
    • Topics
    • Questions
    • Users
    • Badges
  • Home /
avatar image
0
Question by shaystibelman · Feb 24, 2012 at 04:25 PM · playerprefstextfield

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");
Comment
Add comment · Show 2
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Bunny83 · Feb 24, 2012 at 06:00 PM 0
Share

: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.

$$anonymous$$eep in $$anonymous$$d that there's a real-time-preview below your edit field, so you can see how it looks like.

avatar image shaystibelman · Feb 27, 2012 at 09:02 AM 0
Share

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 Replies

· Add your reply
  • Sort: 
avatar image
0
Best Answer

Answer by shaystibelman · Nov 19, 2012 at 02:52 PM

Stupid question, stupid solution:

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

Happy Kwanza everybody!

Comment
Add comment · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image
0

Answer by Bunny83 · Feb 24, 2012 at 06:03 PM

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.

Comment
Add comment · Show 2 · Share
10 |3000 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image shaystibelman · Feb 27, 2012 at 09:03 AM 0
Share

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 $$anonymous$$e");

avatar image shaystibelman · Feb 27, 2012 at 09:12 AM 0
Share

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

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Follow this Question

Answers Answers and Comments

6 People are following this question.

avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Buttons To Use One Text Input Field 1 Answer

How to check if the content of Textfield is equal to PlayerPrefs 1 Answer

How do i Copy Textfield text to my label 1 Answer

GUI.TextField problem, won't update var. 0 Answers

Display Playerpref string in GUI.TextField. 2 Answers


Enterprise
Social Q&A

Social
Subscribe on YouTube social-youtube Follow on LinkedIn social-linkedin Follow on Twitter social-twitter Follow on Facebook social-facebook Follow on Instagram social-instagram

Footer

  • Purchase
    • Products
    • Subscription
    • Asset Store
    • Unity Gear
    • Resellers
  • Education
    • Students
    • Educators
    • Certification
    • Learn
    • Center of Excellence
  • Download
    • Unity
    • Beta Program
  • Unity Labs
    • Labs
    • Publications
  • Resources
    • Learn platform
    • Community
    • Documentation
    • Unity QA
    • FAQ
    • Services Status
    • Connect
  • About Unity
    • About Us
    • Blog
    • Events
    • Careers
    • Contact
    • Press
    • Partners
    • Affiliates
    • Security
Copyright © 2020 Unity Technologies
  • Legal
  • Privacy Policy
  • Cookies
  • Do Not Sell My Personal Information
  • Cookies Settings
"Unity", Unity logos, and other Unity trademarks are trademarks or registered trademarks of Unity Technologies or its affiliates in the U.S. and elsewhere (more info here). Other names or brands are trademarks of their respective owners.
  • Anonymous
  • Sign in
  • Create
  • Ask a question
  • Spaces
  • Default
  • Help Room
  • META
  • Moderators
  • Explore
  • Topics
  • Questions
  • Users
  • Badges