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 Milerael · Feb 26, 2015 at 03:07 PM · androidplayerprefshighscore

How to save data without using PlayerPrefs?

Hello everybody, I read all questions, answers and guides about playerprefs that I could find, nothing helped me, so Im asking if there is another easy way to save data. So you knew what Im trying to do here is my code:

 var controlTexture : Texture2D;
 var controlTexture1 : Texture2D;
 var Score :int;
 var Enemy : Transform;
 var dist:int =1;
 var lost = false;
 var customSkin :GUISkin;
 var highscore:int;
 
     
 
 function start(){
 highscore = PlayerPrefs.GetInt("HighscoreSTR");
 
 }
 
 function OnGUI () {
  GUI.skin = customSkin;
              GUI.Box(new Rect(10,10,150,45), Score.ToString());
              GUI.Box(new Rect(10,60,150,45), highscore.ToString());
 
              
              if (lost) {
               GUI.Box(new Rect(Screen.width/2 -207 ,Screen.height/2 -95  ,420,200),"Well Played!");
               
     if (GUI.Button (Rect (Screen.width/2 -200,Screen.height/2 + 50,150,50), controlTexture)){
     Application.LoadLevel(1);
    }
     if (GUI.Button (Rect (Screen.width/2 +50,Screen.height/2 + 50,150,50), controlTexture1)){
     Application.LoadLevel(0);
     }
     GUI.Label (Rect (Screen.width/2 -20 ,Screen.height/2 -50,500,500), Score.ToString());
     }
     }
     
 
 
 
 function Update () { 
 if (Score >= highscore){
     highscore = Score;
     PlayerPrefs.SetInt("HighscoreSTR", highscore);
     PlayerPrefs.Save();
     }    
     
     
     dist = Vector3.Distance(Enemy.position, transform.position);
         if (dist <=2){
     lost = true;
     }
 
     if (lost){
      Time.timeScale = 0;
     }
     else{
      Time.timeScale = 1;    
 }
     for (var touch : Touch in Input.touches) {
                 if (touch.phase == TouchPhase.Began) {
     if (dist ==3){
     Score = Score + 5 ;
     }
     if (dist ==4){
     Score = Score + 3 ;
     }
     if (dist ==5){
     Score = Score + 1 ;
     }
     
     }
     }
     }
Comment
Add comment · Show 1
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 cariaga · Feb 26, 2015 at 03:10 PM 0
Share

use X$$anonymous$$L or SQLlite

2 Replies

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

Answer by prankard · Feb 26, 2015 at 03:25 PM

Hi Milerael.

Your PlayerPrefs code is actually working the way it should expect.

However, as your 'start' function is lowercase. It isn't running and thus not loading the highscore.

Change

 function start(){

into

 function Start(){

Also, please consider changing:

 if (Score >= highscore){

into

 if (Score > highscore){

To prevent your score being set to the same number on Update.

Comment
Add comment · Show 2 · 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 Milerael · Feb 27, 2015 at 01:06 PM 0
Share

O$$anonymous$$G! Thanks so much, I can't believe I didn't notice that!

avatar image prankard · Feb 27, 2015 at 03:21 PM 0
Share

It usually the simplest errors that break everything spectacularly

avatar image
0

Answer by cariaga · Feb 26, 2015 at 03:11 PM

here is a unity xml example

 http://wiki.unity3d.com/index.php?title=Saving_and_Loading_Data:_XmlSerializer

or you can do an sqlite approach http://wiki.unity3d.com/index.php/SQLite

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 jarado9 · Feb 27, 2015 at 03:27 PM 0
Share

another way http://unity3d.com/learn/tutorials/modules/beginner/live-training-archive/persistence-data-saving-loading

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

4 People are following this question.

avatar image avatar image avatar image avatar image

Related Questions

how to save a highscore 1 Answer

PlayerPrefs not working on android 2 Answers

Player prefs easy highscore? 1 Answer

How to access additional SharedPreferences on Android 0 Answers

Playerprefs don't reset after reinstalling the build on my phone. 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