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 /
This question was closed Feb 16, 2017 at 09:14 PM by Verzus for the following reason:

The question is answered, right answer was accepted

avatar image
0
Question by Verzus · May 28, 2012 at 12:52 PM · c#androidplayerprefssaving

PlayerPrefs not saving

I am fairly new to the concept of PlayerPrefs and have been trying it around so that I would be able to save progress and settings.

While trying to set it up to save what controls the player want to use it doesn't seem to want to save it more then locally.

Please have a look at the code and see if you can find the problem.

Also I don't really think it's relevant but my target build is Android.

Relevant code written in C#.

 public GUIStyle guiStyle;
 public int joystick;
 
 void start()
 {
     refreshJoystickState();
 }
 
 private void refreshJoystickState()
 {
     joystick = PlayerPrefs.GetInt("Joystick");
 }
 
 private void saveJoystickState()
 {
     PlayerPrefs.SetInt("Joystick", joystick);
 }
 void OnGUI () 
 {
     
     if (joystick == 1)
     {
         if(GUI.Button(new Rect(Screen.width / 2 - -200, Screen.height / 2 + 150, 150, 60), "Joystick is active"))
         {
             joystick = 0;
             saveJoystickState();
         }
     }
     if (joystick == 0)
     {
         if(GUI.Button(new Rect(Screen.width / 2 - -200, Screen.height / 2 + 150, 150, 60), "Accelerometer is active"))
         {
             joystick = 1;
             saveJoystickState();
         }
     }
 }

}

Thanks in advance. Verzus

Comment
Add comment
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

1 Reply

  • Sort: 
avatar image
0
Best Answer

Answer by whydoidoit · May 28, 2012 at 01:02 PM

Your Start function has a lowercase "s" and isn't being called. Otherwise it's fine

Comment
Add comment · Show 1 · 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 Verzus · May 28, 2012 at 01:11 PM 0
Share

Haha, such a simple and obvious mistake. Thanks for the help

Follow this Question

Answers Answers and Comments

5 People are following this question.

avatar image avatar image avatar image avatar image avatar image

Related Questions

Player.Prefs not working on android[solved] 2 Answers

Saving public variable data set in inspector? 1 Answer

Need help with using Player Prefs to save number of coins collected. 1 Answer

Player doesn't stop jumping when stop touching the screen[Android] 1 Answer

Android obfuscator 1 Answer


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