Wayback Machinekoobas.hobune.stream
May JUN Jul
Previous capture 12 Next capture
2021 2022 2023
1 capture
12 Jun 22 - 12 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 AmazingDeveloper2 · Oct 17, 2016 at 11:59 AM · c#unity 5saveloadsavegame

How to save data to selected save slot

I make saveGame function and I have 6 slots for saving. How can I say, to which slot should I save data? Should I create variables for each of 6 slots ?

alt text

 private int currentActiveSlot;
 private int latestSaveSlot;

 const int _numberOfSlots = 7;

 string[] dateTime = new string[_numberOfSlots];
 int[] actNumber = new int[_numberOfSlots];
 int[] stepNumber = new int[_numberOfSlots];
 int[] transformPositionX = new int[_numberOfSlots];
 int[] transformPositionY = new int[_numberOfSlots];
 int[] transformPositionZ = new int[_numberOfSlots];
 int[] transformRotationX = new int[_numberOfSlots];
 int[] transformRotationY = new int[_numberOfSlots];
 int[] transformRotationZ = new int[_numberOfSlots];
 int[] task1Completed = new int[_numberOfSlots];
 int[] task2Completed = new int[_numberOfSlots];
 int[] task3Completed = new int[_numberOfSlots];
 int[] task4Completed = new int[_numberOfSlots];
 int[] task5Completed = new int[_numberOfSlots];

 void Start()
 {
     latestSaveSlot = PlayerPrefs.GetInt("latestSaveSlot");
 }

 public void ButtonSave()
 {
     // How to say, to which slot should I save?

     latestSaveSlot = currentActiveSlot;

     PlayerPrefs.SetString("date time", "");
     PlayerPrefs.SetInt("act number", 0);
     PlayerPrefs.SetInt("step number", 0);
     //..
     PlayerPrefs.SetInt("latestSaveSlot", latestSaveSlot);
     PlayerPrefs.SetString("sceneName", SceneManager.GetActiveScene().name);      
     PlayerPrefs.Save();

     dateTime[latestSaveSlot] = PlayerPrefs.GetString("date time");
 }

 public void ButtonLoad()
 {
     dateTime[currentActiveSlot]  = PlayerPrefs.GetString("date time");
     actNumber[currentActiveSlot] = PlayerPrefs.GetInt("act number");
     stepNumber[currentActiveSlot] = PlayerPrefs.GetInt("step number");
     //..
 }

1.jpg (77.0 kB)
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 Cherno · Oct 17, 2016 at 02:57 PM 0
Share

I'd say, use an array with a Length of 6. This way, you only need one variable, and you can easily select one element from it by index.

avatar image AmazingDeveloper2 Cherno · Oct 18, 2016 at 07:20 AM 0
Share

Edited question. Now I use array, but still don't understand, how to say, to which slot should I save with PlayerPrefs.Set?

2 Replies

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

Answer by danivdwerf · Oct 18, 2016 at 07:57 AM

I think you should just make a script which will create a file where it'll save your settings and the name/location can be changed depending on which button you will click

Comment
Add comment · Show 6 · 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 AmazingDeveloper2 · Oct 18, 2016 at 08:04 AM 0
Share

But what the differene? I can save it to file and can save with PlayerPrefs. I just don't want to create 6 variables for each parameter for each slot. I can, but lookig for more beautiful solution

avatar image danivdwerf AmazingDeveloper2 · Oct 18, 2016 at 08:30 AM 0
Share

$$anonymous$$ore code does not mean less beautiful, check out the terms OOP and SRP it will do good.

Ofcourse Unity's build in Functions are handy, but You can create a game with so little effort and $$anonymous$$imum coding. Also, with a save file YOU control everything ins$$anonymous$$d of unity.

avatar image AmazingDeveloper2 danivdwerf · Oct 18, 2016 at 08:36 AM 0
Share

Sorry, but I need example of code, which will help with my problem

Show more comments
Show more comments
avatar image
1

Answer by IgorAherne · Oct 18, 2016 at 10:36 AM

There is a post on habrahabr.ru, which is describing your case exactly. They are using Serialization into XML, but it's all in russian.

You can use google translate nonetheless, here is the link https://habrahabr.ru/post/163071/

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 AmazingDeveloper2 · Oct 18, 2016 at 12:45 PM 1
Share

Я знаю, как сохранять в файл. Вопрос о том, как засунуть PlayerPrefs в массив

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

247 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 avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image avatar image

Related Questions

Multiple Cars not working 1 Answer

Distribute terrain in zones 3 Answers

Saving progress even when I quit the windows app 0 Answers

My balance in the game and my multiplier are not saving, i cant figure out why, any help? 0 Answers

[C#] Save/Load Score stays at 0 even when changed 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