I'm looking at a social interaction app with some game play. I want to create forms and screens so users/players can create personal profiles they can ultimately share over bluetooth/wifi/3G etc. Where and how to I save the data input in the forms? I've found stuff on the player prefs file, but that seems to relate to web games only. Can someone point in the right direction? Examples? Code snippets?
Player Prefs aren't just for web games. They are good for storing data that you do not want to lose between game sessions. However, they can only save strings, floats, and integer variables, so if you need booleans, you'd be best to use an integer as a flag.
The only thing that you need to be careful of when using Player Prefs is that you do not try to access a null variable. If you do this, the Unity editor will not pick up on it and the game will seem fine, until you build it to a device and you get a SIGBUS error. The way I would go about doing it to prevent this is have some class that initializes all Player Prefs on the first scene to ensure that they all exist when they are needed. For example:
This will check to see if the Player Prefs exists, and if it doesn't, it will be created. It is basically a safeguard against SIGBUS errors.
So for what you are looking to do, you can simply save the input from your text fields into Player Prefs, and they can be accessed during any game session.
Hope this helps
answered Dec 14, 2010 at 02:19 PM