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
2
Question by effectoxx · Jan 04, 2012 at 01:15 AM · listsaveloadusers

How to save a progress by user with diferent users

I have a problem I need to have a login System of users , but I can´t relate the Player.Prefs with the screen that display the list of player registered and new users ...... someone that had make somthing like that ?? I need to save the progress of each user....

thanks

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

2 Replies

· Add your reply
  • Sort: 
avatar image
3

Answer by aldonaletto · Jan 04, 2012 at 01:23 AM

You could add the user name or code to the key when saving and restoring its value. If you want to save the score, for instance:

 // save the score:
 PlayerPrefs.SetFloat(username+".Score", score);

 // retrieve the score:
 score = PlayerPrefs.GetFloat(username+".Score", 0);

EDITED: You can save multiple users data this way:

1- Save the usernames with keys like "User"+num. To retrieve all registered users, do something like this:

 var numUsers = PlayerPrefs.GetInt("NumUsers", 0); // how many registered users?
 var usernames = new String[numUsers+1]; // create the user name array...
 for (var n = 1; n <= numUsers; n++){
   usernames[n] = PlayerPrefs.GetString("User"+n, ""); // and load them
 }

2- Show a GUI menu with the users, and let the player select his user name or code;

3- Use the user name or code to find all other user info you need (health, points, weapons, position etc.), always using keys composed by the user name or code plus the info name, like this:

   health = PlayerPrefs.GetFloat(username+".Health", 100);
   points = PlayerPrefs.GetInt(username+".Points", 0);
   hasShotgun = PlayerPrefs.GetInt(username+".Shotgun", 0);
   hasMachinegun = PlayerPrefs.GetInt(username+".MachineGun", 0);
   ...

Obviously, you must save the data with the same format. When an user is registered, for instance, save its data like this:

 var numUser = PlayerPrefs.GetInt("NumUsers", 0);
 numUser += 1; // count this user
 PlayerPrefs.SetInt("NumUsers", numUser); // update users count
 PlayerPrefs.SetString("User"+numUser, username);
 ...


Comment
Add comment · Show 18 · 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 effectoxx · Jan 04, 2012 at 01:26 AM 0
Share

but when the user return how select again their account?? to still playing?

avatar image aldonaletto · Jan 04, 2012 at 05:07 AM 0
Share

Take a look at my answer: I edited it to include other details about multiple users.

avatar image Giannigiardinelli aldonaletto · Mar 03, 2018 at 07:39 AM 0
Share

Hello, I would need help to create several "usernames" via UI of Unity, I am currently looking for a solution by consulting all the possibilities like your written here but I do not come to register "usernames" of the player as well as his backup Who matches his nickname?? I would like to do it via UI ie: "InputFiel" > "button + text" > Clicks the nickname match the player > resets his last backup... With the "serializable" mode

If you can look at my question is to be able to help me I would recognize you thanks in advance

$$anonymous$$y question is here

avatar image effectoxx · Jan 04, 2012 at 04:16 PM 0
Share

ok, ok thanks :)

avatar image akkiDev · Sep 17, 2013 at 06:50 PM 0
Share

hiii... I am new to unity.. I am a flash developer... but now a days it seems to be unity is BEST for using 3d effects, I am developing games for global or social purpose... but i am facing a lot of problems to save my scores.. so i am searching for the same... After R&D I found some samples and tutorials...... check these samples and tutorials, and tell me if you are familiar with all that. Guys if You know anyThing about my problem... then please let me know... thanxs... Gamers waiting for you reply.

avatar image moghes · Sep 17, 2013 at 09:50 PM 0
Share

@aldonaletto this is brilliant! thumbs up

avatar image KittyAnn moghes · Apr 17, 2019 at 06:43 PM 0
Share

@moghes I have converted this to C# BUT I am receiving an error on this line PlayerPrefs.SetString("User"+numUser, username); --------- Visual Studio is telling me "username does not exist in the current context". I do not logically understand how or where to add a "username" statement (OR whatever it is called since SO$$anonymous$$E other people have chosen to pick on me because I am VERY new to coding still). Could you PLEASE help/explain?

avatar image aldonaletto KittyAnn · Apr 18, 2019 at 03:10 PM 0
Share

username is a string variable to which you assign the user name when the user types the desired name. Use some sort of GUI in order to obtain the user name - kind of:

 using UnityEngine;
 using System.Collections;
 
 public class RegisterUser : $$anonymous$$onoBehaviour
 {
     string username = "";
 
     void OnGUI()
     {
         GUI.Label (new Rect (10, 10, 150, 20), "User Name:");
         // User enters username into this text field
         username = GUI.TextField(new Rect(10, 30, 200, 20), username, 25);
         if (GUI.Button(new Rect(150,60,50,25), "ok")){
             int numUser = PlayerPrefs.GetInt("NumUsers", 0);
             numUser += 1; // count this user
             PlayerPrefs.SetInt("NumUsers", numUser); // update users count
             PlayerPrefs.SetString("User"+numUser, username);
         }
     }
 }

That's a very simple GUI code, just an example (and a very ugly one!). You should elaborate it a lot more in order to get something useful. Attach this script to some object in scene.

Show more comments
avatar image
1

Answer by nik_bluebird · Apr 19, 2019 at 11:39 AM

Best way to storing data is Binary Files. Bcoz it is most secure, as data store in terms of zeros and ones.

For more information, go through this link:

https://unity3d.com/learn/tutorials/topics/scripting/introduction-saving-and-loading

I hope it helps.

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

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

11 People are following this question.

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

Related Questions

Set int to object from list? 0 Answers

Why is JSON not saving my Class? 2 Answers

List Contains false after playmode 0 Answers

Saving/Loading class list with SimpleJSON,Saving class list with SimpleJSON 1 Answer

save load list 3 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