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 grendayzer77 · May 05, 2014 at 09:07 AM · iosmobilegamesaveload

Problem Saving game progress

Hi, i'm new in Unity, and i have a question about saving game progress. I create a simple code to write on a text file to save Levels Number, so i do this -System.IO.File.WriteAllText();- it works perfectly in Unity, but once i want to build it for ios, i have an error message about AssetDatabase.Refresh(); unknown, when i remove this, my code didn't work anymore, i can load data information from the TextAsset file, but can't write or can't refresh the asset. So i wonder if this is the best way to do that, and if there is a solution to this.

PS : Working on 2D game for ios (not an online Game)

Thanks. Best regards

The Code :

import System.IO;

function Update() { if (Input.GetMouseButtonDown(0)) { var hit : RaycastHit2D = Physics2D.Raycast(Camera.main.ScreenToWorldPoint(Input.mousePosition), Vector2.zero); if(hit.collider.name == "Button-Enter") { System.IO.File.WriteAllText(Application.dataPath + "/Save-Levels.txt", "3"); AssetDatabase.Refresh(); } } }

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

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

Answer by fafase · May 05, 2014 at 09:08 AM

You cannot use PlayerPrefs?

https://docs.unity3d.com/Documentation/ScriptReference/PlayerPrefs.html

Comment
Add comment · Show 3 · 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 grendayzer77 · May 05, 2014 at 10:08 AM 0
Share

Sorry to ask this, what is that and i really don't know if i can use it or not. i read the URL, and it seems to be a kind of storage to save. PlayerPrefs.Save, is that what i should look for ? thanks again.

avatar image fafase · May 05, 2014 at 11:12 AM 0
Share

It is unity saving class. It saves information in some deep registry of your machine. I would also think it is encrypted. Good points, it works the same regardless the platform and makes hacking a tight little harder (though not impossible). Litle downside, you can only save int, float or string. But you can create a method to store many info in one string

 "Pl:Name,L:100,W:Sw" 

See this line above save the player's name, his life value and the weapon he is using (sword). When retrieving, you just parse the other way around.

avatar image grendayzer77 · May 05, 2014 at 11:20 AM 1
Share

Thanks that work. here is the script i used :

To set : PlayerPrefs.SetInt("SaveLevel", 1); To load level number : PlayerPrefs.GetInt("SaveLevel");

Thanks again

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

21 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

Related Questions

Drag and Drop menu and Save load game. 0 Answers

Unity load last level (save and load game) 0 Answers

General mobile game developing questions 0 Answers

Save Game - What do I need? 1 Answer

Save/ Load game script in main menu 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