Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

My Save Script Work on Computer But It's Not Working on Android

Discussion in 'Scripting' started by RedsonB, Apr 14, 2020.

  1. RedsonB

    RedsonB

    Joined:
    Apr 12, 2019
    Posts:
    7
    Code (CSharp):
    1.  private void LoadSystem()
    2.     {
    3.    
    4.         string path = Application.dataPath + "/GameData.json";
    5.         if (File.Exists(path))
    6.         {
    7.             string jsonString = File.ReadAllText(path);
    8.  
    9.             //SaveData saveData = new SaveData();
    10.             saveData = JsonUtility.FromJson<SaveData>(jsonString);
    11.  
    12.  
    13.             money = saveData.money;
    14.             currentEarnings = saveData.currentEarnings;
    15.  
    16.             for (int i = 0; i < saveData.carData.Length; i++)
    17.             {
    18.                 string appName = "Car" + (i + 1).ToString() + "Btn";
    19.                 btn = GameObject.Find(appName).GetComponent<Button>();
    20.                 btn.interactable = saveData.carData[i];
    21.             }
    22.             for (int i = 0; i < saveData.petData.Length; i++)
    23.             {
    24.                 string appName = "Pet" + (i + 1).ToString() + "Btn";
    25.                 btn = GameObject.Find(appName).GetComponent<Button>();
    26.                 btn.interactable = saveData.petData[i];
    27.             }
    28.             for (int i = 0; i < saveData.appData.Length; i++)
    29.             {
    30.                 string appName = "App" + (i + 1).ToString() + "Btn";
    31.                 btn = GameObject.Find(appName).GetComponent<Button>();
    32.                 btn.interactable = saveData.appData[i];
    33.             }
    34.             for (int i = 0; i < saveData.houseData.Length; i++)
    35.             {
    36.                 string appName = "House" + (i + 1).ToString() + "Btn";
    37.                 btn = GameObject.Find(appName).GetComponent<Button>();
    38.                 btn.interactable = saveData.houseData[i];
    39.             }
    40.  
    41.  
    42.  
    43.  
    44.         }
    45.         else
    46.         {
    47.             saveData.money = money;
    48.             saveData.currentEarnings = currentEarnings;
    49.             for (int i = 0; i < saveData.carData.Length; i++)
    50.             {
    51.                 string appName = "Car" + (i + 1).ToString() + "Btn";
    52.                 btn = GameObject.Find(appName).GetComponent<Button>();
    53.                 btn.interactable = saveData.carData[0];
    54.             }
    55.             for (int i = 0; i < saveData.petData.Length; i++)
    56.             {
    57.                 string appName = "Pet" + (i + 1).ToString() + "Btn";
    58.                 btn = GameObject.Find(appName).GetComponent<Button>();
    59.                 btn.interactable = saveData.petData[0];
    60.             }
    61.             for (int i = 0; i < saveData.appData.Length; i++)
    62.             {
    63.                 string appName = "App" + (i + 1).ToString() + "Btn";
    64.                 btn = GameObject.Find(appName).GetComponent<Button>();
    65.                 btn.interactable = saveData.appData[0];
    66.             }
    67.             for (int i = 0; i < saveData.houseData.Length; i++)
    68.             {
    69.                 string appName = "House" + (i + 1).ToString() + "Btn";
    70.                 btn = GameObject.Find(appName).GetComponent<Button>();
    71.                 btn.interactable = saveData.houseData[0];
    72.             }
    73.  
    74.  
    75.         }
    76.     }

    Code (CSharp):
    1.  public void SaveSystem()
    2.     {
    3.  
    4.         saveData.money = money;
    5.         saveData.currentEarnings = currentEarnings;
    6.  
    7.         for (int i = 0; i < saveData.carData.Length; i++)
    8.         {
    9.             string appName = "Car" + (i+1).ToString() + "Btn";
    10.             btn = GameObject.Find(appName).GetComponent<Button>();
    11.             if (btn.interactable == false)
    12.             {
    13.                 saveData.carData[i] = false;
    14.             }
    15.         }
    16.         for (int i = 0; i < saveData.petData.Length; i++)
    17.         {
    18.             string appName = "Pet" + (i + 1).ToString() + "Btn";
    19.             btn = GameObject.Find(appName).GetComponent<Button>();
    20.             if (btn.interactable == false)
    21.             {
    22.                 saveData.petData[i] = false;
    23.             }
    24.         }
    25.         for (int i = 0; i < saveData.houseData.Length; i++)
    26.         {
    27.          
    28.             string appName = "House" + (i + 1).ToString() + "Btn";
    29.             btn = GameObject.Find(appName).GetComponent<Button>();
    30.             if (btn.interactable == false)
    31.             {
    32.                 saveData.houseData[i] = false;
    33.             }
    34.         }
    35.         for (int i = 0; i < saveData.appData.Length; i++)
    36.         {
    37.             string appName = "App" + (i + 1).ToString() + "Btn";
    38.             btn = GameObject.Find(appName).GetComponent<Button>();
    39.             if (btn.interactable == false)
    40.             {
    41.                 saveData.appData[i] = false;
    42.             }
    43.         }
    44.  
    45.  
    46.         string savestatePath = Path.Combine(Application.dataPath, "GameData.json");
    47.         File.WriteAllText(savestatePath, JsonUtility.ToJson(saveData, true));
    48.  
    49.  
    50.     }
     
  2. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    Joe-Censored likes this.
  3. RedsonB

    RedsonB

    Joined:
    Apr 12, 2019
    Posts:
    7
  4. Kurt-Dekker

    Kurt-Dekker

    Joined:
    Mar 16, 2013
    Posts:
    36,971
    Time to break out
    adb logcat
    and put in some strategic
    Debug.Log()
    statements in your code to try and track down what's going wrong!
     
    Joe-Censored likes this.