• 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 /
  • Help Room /
avatar image
0
Question by Timmsyz · Feb 26, 2017 at 06:42 AM · androidsavingparseparsing

Error: Input string was not in the correct format - HELP!

I am creating an android game hill climb racing style. but I have a problem with the progress saving and and car upgrading. alt text

 using UnityEngine;
 using System.Collections;
 using UnityEngine.SceneManagement;
 using UnityEngine.UI;
 
 public class MenuScript : MonoBehaviour {
 
     public GameObject levelChanger;
     public GameObject exitPanel;
     public GameObject garagePanel;
     public Image[] cars;
     public Text coinText;
     public Button[] bttns;
     public Text[] carsText;
     public string[] levels;
     private char del = 'f';
     public Button[] updateBttns;
     saveToJson stj = new saveToJson();
     private int carForT;
 
     public GameObject ScrollPanel;
     public GameObject JeepPanel;
     public GameObject SportCarPanel;
     public Button chooseJeepBttn;
     public Button chooseSportCarBttn;
     public GameObject JeepUpgradePanel;
     public GameObject SportCarUpgradePanel;
     public Button UpgradeJeepButton;
     public Button UpgradeSportCarButton;
 
 
 
 
 
 
     void Awake()
     {
         if (!PlayerPrefs.HasKey("sv"))
         {
             for (int i = 0; i < stj.t.Length; i++) stj.t[i] = "0f0f0";
             string json = JsonUtility.ToJson(stj);
             PlayerPrefs.SetString("sv", json);
         }
         else
         {
             stj = JsonUtility.FromJson<saveToJson>(PlayerPrefs.GetString("sv"));
             for (int i = 0; i < stj.lvls.Length; i++) if (stj.lvls[i] == 3) { bttns[i].interactable = true; carsText[i].gameObject.SetActive(false); }
             if (data.gameStarted) data.dat(stj.coins, stj.car, stj.t, stj.lvls);
         }
     }
 
 
     void Start()
     {
         cars[data.car].color = Color.white;
     }
 
     void Update()
     {
         if (garagePanel.activeSelf == true && Input.GetKeyDown(KeyCode.Escape))
         {
             garagePanel.SetActive(false);
         }
         else if (levelChanger.activeSelf == true && Input.GetKeyDown(KeyCode.Escape))
         {
             levelChanger.SetActive(false);
         }
         else if (exitPanel.activeSelf == false && Input.GetKeyDown(KeyCode.Escape))
         {
             exitPanel.SetActive(true);
         }
         else if (Input.GetKeyDown(KeyCode.Escape))
         {
             exitPanel.SetActive(false);
         }
         coinText.text = PlayerPrefs.GetInt("coins").ToString();
 
     }
         
     public void OnClickExitExit()
     {
         exitPanel.SetActive(false);
     }
     public void OnClickExitPanel()
     {
         exitPanel.SetActive(true);
     }
     public void OnClickExitGaragePanel()
     {
         garagePanel.SetActive(false);
     }
     public void OnClickExitScrollPanel()
     {
         ScrollPanel.SetActive(false);
     }
     public void OpenJeepUpgrade()
     {
         JeepUpgradePanel.SetActive(true);
     }
     public void OpenSportCarUpgrade()
     {
         SportCarUpgradePanel.SetActive (true);
     }
         public void closeJeepUpgrader(){
         JeepUpgradePanel.SetActive (false);
     }
     public void closeSportCarUpgrader(){
         SportCarUpgradePanel.SetActive (false);
     }
         
     public void OnClickStart()
     {
         levelChanger.SetActive(true);
     }
     public void OnClickExit()
     {
         Application.Quit();
     }
     public void levelBttns(int level)
     {
         data.gameStarted = false;
         SceneManager.LoadScene(level);
     }
     public void carChanger(int car)
     {
         data.car = car;
         for (int c = 0; c < cars.Length; c++)
         {
             cars[c].color = Color.white;
             cars[car].color = Color.white;
         }
     }
     public void carTuning(int carPart)
     {
         string[] carforT = data.t[carForT].Split(del);
         int updateState = int.Parse(carforT[carPart]) + 1;
         if (updateState <= 3 && 5 * updateState <= data.coins)
         {
             carforT[carPart] = updateState.ToString();
             data.t[carForT] = carforT[0] + "f" + carforT[1] + "f" + carforT[2];
             data.coins -= 5 * updateState;
         }
         if (int.Parse(carforT[carPart]) == 3 || stj.coins < 5 * updateState)
         {
             updateBttns[carPart].interactable = false;
         }
         print(data.t[carForT]);
     }
     public void carForTun(int car)
     {
         carForT = car;
     }
     void OnApplicationQuit()
     {
         stj.dat(data.coins,data.car,data.t,data.lvls);
         string json = JsonUtility.ToJson(stj);
         PlayerPrefs.SetString("sv", json);
     }
 }
 public class saveToJson
 {
     public int coins = 0,car = 0;
     public string[] t = new string[3];
     public int[] lvls = new int[2];
 
     public void dat(int coins, int car, string[] t, int[] lvls)
     {
         this.coins = coins;
         this.car = car;
         this.t = t;
         this.lvls = lvls;
     }
 }
 public static class data
 {
     public static int coins = 0, car = 0;
     public static string[] t = new string[3];
     public static int[] lvls = new int[2];
     public static bool gameStarted = true;
 
     public static void dat(int coins,int car, string[] t,int[] lvls)
     {
         data.coins = coins;
         data.car = car;
         data.t = t;
         data.lvls = lvls;
     }
 }


снимок-экрана-5.png (280.8 kB)
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

0 Replies

· Add your reply
  • Sort: 

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.

Welcome to Unity Answers

The best place to ask and answer questions about development with Unity.

To help users navigate the site we have posted a site navigation guide.

If you are a new user to Unity Answers, check out our FAQ for more information.

Make sure to check out our Knowledge Base for commonly asked Unity questions.

If you are a moderator, see our Moderator Guidelines page.

We are making improvements to UA, see the list of changes.



Follow this Question

Answers Answers and Comments

150 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

Related Questions

saving IAP data on a database 0 Answers

Data not Saving in Android Using Unity Persistance Saving Training. 1 Answer

iOS/Android Save and Load Texture 0 Answers

Playerprefs don't work on Android 0 Answers

PlayerPrefs not working on android 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