Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

HELP Binary save system

Discussion in 'Scripting' started by SonGokuBg, May 7, 2020.

  1. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    it will be so cool if I can say objArray["Red"];
     
  2. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    if you really want to do it that way you can do

    Code (CSharp):
    1.  
    2.  
    3. switch (colorid)
    4.         {
    5.             case "Red":
    6.                 return objArray[1];
    7.                 break;
    8.  
    9. }
    10.  
    11.  
    12.  
    but you are just making it harder for yourself haha
     
  3. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    I am just not sure how I will remember the numbers.
    Btw why this is not SaveClass sv = new SaveClass();
    Code (CSharp):
    1.  sv = new SaveClass();
     
  4. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    because you already have it earlier

    Code (CSharp):
    1. public SaveClass sv;
     
  5. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    I just added an array for the owned materials
    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.IO;
    5. using System.Runtime.Serialization.Formatters.Binary;
    6. using UnityEngine;
    7.  
    8. public class SaveSystem : MonoBehaviour
    9. {
    10.     public BinaryFormatter bf = new BinaryFormatter();
    11.     public FileStream fs;
    12.     public SaveClass sv;
    13.  
    14.     public float Coins;
    15.     public bool IsLaserBought;
    16.     public string CurrentMaterial;
    17.     public bool[] isMaterialOwned;
    18.  
    19.     public bool TriggerSave;
    20.     public bool TriggerLoad;
    21.  
    22.     [Serializable]
    23.     public class SaveClass
    24.     {
    25.         public float Save_Coins;
    26.         public bool Save_IsLaserBought;
    27.         public string Save_CurrentMaterial;
    28.         public bool[] Save_isMaterialOwned;
    29.     }
    30.  
    31.     public void SaveMethod()
    32.     {
    33.  
    34.         if (Directory.Exists(Application.persistentDataPath + "/Save/") == false)
    35.         {
    36.             Debug.Log("creating dir");
    37.             Directory.CreateDirectory(Application.persistentDataPath + "/Save/");
    38.         }
    39.  
    40.         fs = File.Create(Application.persistentDataPath + "/Save/saved.coins");
    41.  
    42.         sv = new SaveClass();
    43.         sv.Save_Coins = Coins;
    44.         sv.Save_IsLaserBought = IsLaserBought;
    45.         sv.Save_CurrentMaterial = CurrentMaterial;
    46.         sv.Save_isMaterialOwned = isMaterialOwned;
    47.         bf.Serialize(fs, sv);
    48.  
    49.         fs.Close();
    50.  
    51.     }
    52.  
    53.  
    54.     public void LoadMethod()
    55.     {
    56.  
    57.         if (File.Exists(Application.persistentDataPath + "/Save/saved.coins") == true)
    58.         {
    59.  
    60.             fs = File.Open(Application.persistentDataPath + "/Save/saved.coins", FileMode.Open);
    61.             sv = (SaveClass)bf.Deserialize(fs);
    62.  
    63.             Coins = sv.Save_Coins;
    64.             IsLaserBought = sv.Save_IsLaserBought;
    65.             CurrentMaterial = sv.Save_CurrentMaterial;
    66.             isMaterialOwned = sv.Save_isMaterialOwned;
    67.             Debug.Log("Coins: " + Coins);
    68.             Debug.Log("IsLaserBought: " + IsLaserBought);
    69.             Debug.Log("Current Material: " + CurrentMaterial);
    70.             fs.Close();
    71.  
    72.  
    73.         }
    74.  
    75.  
    76.     }
    77.  
    78.     void Update()
    79.     {
    80.         // FOR THE INSPECTOR
    81.         if (TriggerSave == true)
    82.         {
    83.             SaveMethod();
    84.             TriggerSave = false;
    85.         }
    86.         if (TriggerLoad == true)
    87.         {
    88.             LoadMethod();
    89.             TriggerLoad = false;
    90.         }
    91.     }
    92.  
    93. }
    94.  
     
  6. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    lol, I need to delete the save file everytime I want to change the array size
     
  7. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    well you are trying to load new things, how can the old save know about the new things that didnt exist when you saved it
     
  8. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    I don't understand what exactly this is doing
    Code (CSharp):
    1.  
    2. objChildren = new list<int>[ objArray.length ];
    3. for( int i = 0; i< objArray.Length; i++){
    4. for( int j = 0; j < objArray[i].transform.childcount; i++){
    5. objChildren[i].add(objArray[i].transform.getchild(j).getcomponent<objectIdentif>().obj_ID);
    6. }
    7. }
    8.  
     
  9. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    finds every children in your objects and saves the id in a list

    then when you load you send them to their parent
     
  10. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    These are the things that I want to move and save (inside the "Content")

    (there are buttons btw)
    upload_2020-5-29_19-38-26.png
     
  11. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    create an object array and place

    element 0 - content
    element 1 - defaultwhite
    element 2 - red

    etc...

    and then each object must have a id script like i showed you

    and on their obj_ID write

    0
    1
    2

    etc...
     
  12. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    where I am saying where to move it ? what is doing line 7?
    Code (CSharp):
    1.  
    2. for( int i = 0; i < objChildren.length; i++){
    3. for( int j =0 ; j < objChildren[j].count; j++){
    4. objArray[j].transform.setparent(objArray[i]);
     
  13. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
  14. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    puts all objects that were child to the parent
     
  15. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    which one is the parent???
    And I only need to do that when I buy the item
     
  16. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    you dont want to load it? if not you can ignore all that code
     
  17. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    1)I am buying a color.
    2) saveSystem.isMaterialOwned[the color that I bought] = true;
    3) I am moving that color object to another parent.
    4) I need to save that
    5) and maybe load it???
     
  18. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    well whats the point of save if you dont want to load =)
     
  19. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    but if you are doing it like that I have an easy fix for you

    Code (CSharp):
    1. if ( saveSystem.isMaterialOwned[the color that I bought] == true){
    2.  
    3. the color that I bought.setparent(content.transform);
    4.  
    5. }
     
  20. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    and I need to save only that
     
  21. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    yes
     
  22. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    Did you test that? I really don't get it upload_2020-5-30_14-59-59.png
     
  23. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    needs to be sv.ObjChildren, you need to add ObjChildren to your save class
     
  24. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    Code (CSharp):
    1. using System.Collections;
    2. using UnityEngine;
    3.  
    4. public class MaterialsID : MonoBehaviour
    5. {
    6.     public int DefaultWhite_0;
    7.     public int Red_1;
    8.     public int Blue_2;
    9.     public int Green_3;
    10.     public int Pink_4;
    11.  
    12. }
    13.  
    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.IO;
    5. using System.Runtime.Serialization.Formatters.Binary;
    6. using UnityEngine;
    7.  
    8. public class SaveSystem : MonoBehaviour
    9. {
    10.     public BinaryFormatter bf = new BinaryFormatter();
    11.     public FileStream fs;
    12.     public SaveClass sv;
    13.     public GameObject[] objArray;
    14.  
    15.     public float Coins;
    16.     public bool IsLaserBought;
    17.     public string CurrentMaterial;
    18.     public bool[] isMaterialOwned;
    19.  
    20.     public list<int>[] objChildren;
    21.  
    22.  
    23.     public bool TriggerSave;
    24.     public bool TriggerLoad;
    25.  
    26.     [Serializable]
    27.     public class SaveClass
    28.     {
    29.         public float Save_Coins;
    30.         public bool Save_IsLaserBought;
    31.         public string Save_CurrentMaterial;
    32.         public bool[] Save_isMaterialOwned;
    33.  
    34.  
    35.         public list<int>[] Save_objChildren;
    36.     }
    37.  
    38.     public void SaveMethod()
    39.     {
    40.  
    41.         if (Directory.Exists(Application.persistentDataPath + "/Save/") == false)
    42.         {
    43.             Debug.Log("creating dir");
    44.             Directory.CreateDirectory(Application.persistentDataPath + "/Save/");
    45.         }
    46.  
    47.         fs = File.Create(Application.persistentDataPath + "/Save/saved.coins");
    48.  
    49.         sv = new SaveClass();
    50.         sv.Save_Coins = Coins;
    51.         sv.Save_IsLaserBought = IsLaserBought;
    52.         sv.Save_CurrentMaterial = CurrentMaterial;
    53.         sv.Save_isMaterialOwned = isMaterialOwned;
    54.  
    55.  
    56.         objChildren = new list<int>[objArray.Length];
    57.  
    58.         for (int i = 0; i < objArray.Length; i++)
    59.         {
    60.  
    61.             for (int j = 0; j < objArray[i].transform.childCount; i++)
    62.             {
    63.  
    64.                 sv.Save_objChildren[i].add(objArray[i].transform.GetChild(j).GetComponent<MaterialsID>());
    65.  
    66.             }
    67.  
    68.         }
    69.         bf.Serialize(fs, sv);
    70.  
    71.         fs.Close();
    72.  
    73.     }
    74.  
    75.  
    76.     public void LoadMethod()
    77.     {
    78.  
    79.         if (File.Exists(Application.persistentDataPath + "/Save/saved.coins") == true)
    80.         {
    81.  
    82.             fs = File.Open(Application.persistentDataPath + "/Save/saved.coins", FileMode.Open);
    83.             sv = (SaveClass)bf.Deserialize(fs);
    84.  
    85.             Coins = sv.Save_Coins;
    86.             IsLaserBought = sv.Save_IsLaserBought;
    87.             CurrentMaterial = sv.Save_CurrentMaterial;
    88.             isMaterialOwned = sv.Save_isMaterialOwned;
    89.             Debug.Log("Coins: " + Coins);
    90.             Debug.Log("IsLaserBought: " + IsLaserBought);
    91.             Debug.Log("Current Material: " + CurrentMaterial);
    92.             fs.Close();
    93.  
    94.  
    95.         }
    96.  
    97.  
    98.     }
    99.  
    100.     void Update()
    101.     {
    102.         // FOR THE INSPECTOR
    103.         if (TriggerSave == true)
    104.         {
    105.             SaveMethod();
    106.             TriggerSave = false;
    107.         }
    108.         if (TriggerLoad == true)
    109.         {
    110.             LoadMethod();
    111.             TriggerLoad = false;
    112.         }
    113.     }
    114.  
    115. }
    116.  
     
  25. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    Code (CSharp):
    1.  
    2. using System.Collections;
    3. using UnityEngine;
    4.  
    5. public class MaterialsID : MonoBehaviour
    6. {
    7. //0 = content
    8. //1 = white
    9. //2 = red
    10. //etc..
    11.     public int mat_ID;
    12.  
    13. }
    14.  
    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.IO;
    5. using System.Runtime.Serialization.Formatters.Binary;
    6. using UnityEngine;
    7.  
    8. public class SaveSystem : MonoBehaviour
    9. {
    10.     public BinaryFormatter bf = new BinaryFormatter();
    11.     public FileStream fs;
    12.     public SaveClass sv;
    13.     public GameObject[] objArray;
    14.  
    15.     public float Coins;
    16.     public bool IsLaserBought;
    17.     public string CurrentMaterial;
    18.     public bool[] isMaterialOwned;
    19.  
    20.     public list<int>[] objChildren;
    21.  
    22.  
    23.     public bool TriggerSave;
    24.     public bool TriggerLoad;
    25.  
    26.     [Serializable]
    27.     public class SaveClass
    28.     {
    29.         public float Save_Coins;
    30.         public bool Save_IsLaserBought;
    31.         public string Save_CurrentMaterial;
    32.         public bool[] Save_isMaterialOwned;
    33.  
    34.  
    35.         public list<int>[] Save_objChildren;
    36.     }
    37.  
    38.     public void SaveMethod()
    39.     {
    40.  
    41.         if (Directory.Exists(Application.persistentDataPath + "/Save/") == false)
    42.         {
    43.             Debug.Log("creating dir");
    44.             Directory.CreateDirectory(Application.persistentDataPath + "/Save/");
    45.         }
    46.  
    47.         fs = File.Create(Application.persistentDataPath + "/Save/saved.coins");
    48.  
    49.         sv = new SaveClass();
    50.         sv.Save_Coins = Coins;
    51.         sv.Save_IsLaserBought = IsLaserBought;
    52.         sv.Save_CurrentMaterial = CurrentMaterial;
    53.         sv.Save_isMaterialOwned = isMaterialOwned;
    54.  
    55.  
    56.         sv.Save_objChildren = new list<int>[objArray.Length];
    57.  
    58.         for (int i = 0; i < objArray.Length; i++)
    59.         {
    60.  
    61.             for (int j = 0; j < objArray[i].transform.childCount; i++)
    62.             {
    63.  
    64.                 sv.Save_objChildren[i].Add(objArray[i].transform.GetChild(j).GetComponent<MaterialsID>().mat_ID);
    65.  
    66.             }
    67.  
    68.         }
    69.         bf.Serialize(fs, sv);
    70.  
    71.         fs.Close();
    72.  
    73.     }
    74.  
    75.  
    76.     public void LoadMethod()
    77.     {
    78.  
    79.         if (File.Exists(Application.persistentDataPath + "/Save/saved.coins") == true)
    80.         {
    81.  
    82.             fs = File.Open(Application.persistentDataPath + "/Save/saved.coins", FileMode.Open);
    83.             sv = (SaveClass)bf.Deserialize(fs);
    84.  
    85.             Coins = sv.Save_Coins;
    86.             IsLaserBought = sv.Save_IsLaserBought;
    87.             CurrentMaterial = sv.Save_CurrentMaterial;
    88.             isMaterialOwned = sv.Save_isMaterialOwned;
    89.             Debug.Log("Coins: " + Coins);
    90.             Debug.Log("IsLaserBought: " + IsLaserBought);
    91.             Debug.Log("Current Material: " + CurrentMaterial);
    92.  
    93.  
    94. for( int i = 0; i <sv.Save_objChildren.length; i++){
    95.  
    96. for( int j =0 ; j < sv.Save_objChildren[i].count; j++){
    97.  
    98. objArray[j].transform.setparent(objArray[i]);
    99. }
    100. }
    101.  
    102.  
    103.             fs.Close();
    104.  
    105.  
    106.         }
    107.  
    108.  
    109.     }
    110.  
    111.     void Update()
    112.     {
    113.         // FOR THE INSPECTOR
    114.         if (TriggerSave == true)
    115.         {
    116.             SaveMethod();
    117.             TriggerSave = false;
    118.         }
    119.         if (TriggerLoad == true)
    120.         {
    121.             LoadMethod();
    122.             TriggerLoad = false;
    123.         }
    124.     }
    125.  
    126. }
    127.  
     
    Last edited: May 30, 2020
  26. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    theres a mistake I edited the above post,

    your parent object also needs the materialsID script
     
  27. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    upload_2020-5-30_17-35-21.png
     
  28. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    missing ; on

    Code (CSharp):
    1.  for (int j = 0; j < objArray[i].transform.childCount; j++)
    2.  
    also you need to write count with capital C, use visual studio to correct this simple error
     
  29. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    I tried that of course. it doesn't accept Count and Add
     
  30. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    because you also need to put big L on list, you have to check all spots

    Code (CSharp):
    1.  public list<int>[] objChildren;
    needs to be List
     
  31. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    Well, I didn't know it's with capital L. I didn't have errors. Maybe list is a static class
     
  32. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    Man, Why I can't do it..Am I so stupid? I just don't understand your way and that's why... And I am getting errors upload_2020-6-1_11-31-19.png
     
  33. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    hmm delete old save
     
  34. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    i tried
     
  35. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    delete the whole folder then, if it still doesnt work copy paste whole script so i can check =)
     
  36. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    I doesn't work at all.. I have an idea, if it doesn't succeed I will message you
     
  37. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.IO;
    5. using System.Runtime.Serialization.Formatters.Binary;
    6. using UnityEngine;
    7.  
    8. public class SaveSystem : MonoBehaviour
    9. {
    10.     public BinaryFormatter bf = new BinaryFormatter();
    11.     public FileStream fs;
    12.     public SaveClass sv;
    13.     public GameObject[] materialsObjects;
    14.  
    15.     public float Coins;
    16.     public bool IsLaserBought;
    17.     public string CurrentMaterial;
    18.     public bool[] isMaterialOwned;
    19.  
    20.     public Transform cosmeticsInventory;
    21.  
    22.  
    23.     public bool TriggerSave;
    24.     public bool TriggerLoad;
    25.  
    26.     [Serializable]
    27.     public class SaveClass
    28.     {
    29.         public float Save_Coins;
    30.         public bool Save_IsLaserBought;
    31.         public string Save_CurrentMaterial;
    32.         public bool[] Save_isMaterialOwned;
    33.  
    34.         public GameObject[] Save_materialsObjects;
    35.     }
    36.  
    37.     public void SaveMethod()
    38.     {
    39.  
    40.         if (Directory.Exists(Application.persistentDataPath + "/Save/") == false)
    41.         {
    42.             Debug.Log("creating dir");
    43.             Directory.CreateDirectory(Application.persistentDataPath + "/Save/");
    44.         }
    45.  
    46.         fs = File.Create(Application.persistentDataPath + "/Save/saved.coins");
    47.  
    48.         sv = new SaveClass();
    49.         sv.Save_Coins = Coins;
    50.         sv.Save_IsLaserBought = IsLaserBought;
    51.         sv.Save_CurrentMaterial = CurrentMaterial;
    52.         sv.Save_isMaterialOwned = isMaterialOwned;
    53.  
    54.         sv.Save_materialsObjects = materialsObjects;
    55.  
    56.         bf.Serialize(fs, sv);
    57.  
    58.         fs.Close();
    59.  
    60.     }
    61.  
    62.  
    63.     public void LoadMethod()
    64.     {
    65.  
    66.         if (File.Exists(Application.persistentDataPath + "/Save/saved.coins") == true)
    67.         {
    68.  
    69.             fs = File.Open(Application.persistentDataPath + "/Save/saved.coins", FileMode.Open);
    70.             sv = (SaveClass)bf.Deserialize(fs);
    71.  
    72.             Coins = sv.Save_Coins;
    73.             IsLaserBought = sv.Save_IsLaserBought;
    74.             CurrentMaterial = sv.Save_CurrentMaterial;
    75.             isMaterialOwned = sv.Save_isMaterialOwned;
    76.             for (int i = 0; i < isMaterialOwned.Length; i++)
    77.             {
    78.                 materialsObjects[i].transform.SetParent(cosmeticsInventory);
    79.             }
    80.  
    81.             materialsObjects = sv.Save_materialsObjects;
    82.             Debug.Log("Coins: " + Coins);
    83.             Debug.Log("IsLaserBought: " + IsLaserBought);
    84.             Debug.Log("Current Material: " + CurrentMaterial);
    85.  
    86.  
    87.             fs.Close();
    88.  
    89.  
    90.         }
    91.  
    92.  
    93.     }
    94.  
    95.     void Update()
    96.     {
    97.         // FOR THE INSPECTOR
    98.         if (TriggerSave == true)
    99.         {
    100.             SaveMethod();
    101.             TriggerSave = false;
    102.         }
    103.         if (TriggerLoad == true)
    104.         {
    105.             LoadMethod();
    106.             TriggerLoad = false;
    107.         }
    108.     }
    109.  
    110. }
    111.  
    112.  
    i thought it will work upload_2020-6-1_17-41-41.png
     
  38. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522

    you cant serialize game objects, you need to remove

    Code (CSharp):
    1.     public GameObject[] Save_materialsObjects;
    from your save class, you cant do that
     
  39. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    Ok, this works!
    Code (CSharp):
    1. using System;
    2. using System.Collections;
    3. using System.Collections.Generic;
    4. using System.IO;
    5. using System.Runtime.Serialization.Formatters.Binary;
    6. using UnityEngine;
    7.  
    8. public class SaveSystem : MonoBehaviour
    9. {
    10.     public BinaryFormatter bf = new BinaryFormatter();
    11.     public FileStream fs;
    12.     public SaveClass sv;
    13.     public GameObject[] materialsObjects;
    14.  
    15.     public float Coins;
    16.     public bool IsLaserBought;
    17.     public string CurrentMaterial;
    18.     public bool[] isMaterialOwned;
    19.  
    20.     public Transform cosmeticsInventory;
    21.  
    22.  
    23.     public bool TriggerSave;
    24.     public bool TriggerLoad;
    25.  
    26.     [Serializable]
    27.     public class SaveClass
    28.     {
    29.         public float Save_Coins;
    30.         public bool Save_IsLaserBought;
    31.         public string Save_CurrentMaterial;
    32.         public bool[] Save_isMaterialOwned;
    33.     }
    34.  
    35.     public void SaveMethod()
    36.     {
    37.  
    38.         if (Directory.Exists(Application.persistentDataPath + "/Save/") == false)
    39.         {
    40.             Debug.Log("creating dir");
    41.             Directory.CreateDirectory(Application.persistentDataPath + "/Save/");
    42.         }
    43.  
    44.         fs = File.Create(Application.persistentDataPath + "/Save/saved.coins");
    45.  
    46.         sv = new SaveClass();
    47.         sv.Save_Coins = Coins;
    48.         sv.Save_IsLaserBought = IsLaserBought;
    49.         sv.Save_CurrentMaterial = CurrentMaterial;
    50.         sv.Save_isMaterialOwned = isMaterialOwned;
    51.  
    52.         bf.Serialize(fs, sv);
    53.  
    54.         fs.Close();
    55.  
    56.     }
    57.  
    58.  
    59.     public void LoadMethod()
    60.     {
    61.  
    62.         if (File.Exists(Application.persistentDataPath + "/Save/saved.coins") == true)
    63.         {
    64.  
    65.             fs = File.Open(Application.persistentDataPath + "/Save/saved.coins", FileMode.Open);
    66.             sv = (SaveClass)bf.Deserialize(fs);
    67.  
    68.             Coins = sv.Save_Coins;
    69.             IsLaserBought = sv.Save_IsLaserBought;
    70.             CurrentMaterial = sv.Save_CurrentMaterial;
    71.             isMaterialOwned = sv.Save_isMaterialOwned;
    72.             for (int i = 0; i < isMaterialOwned.Length; i++)
    73.             {
    74.                 if (isMaterialOwned[i] == true)
    75.                 {
    76.                     materialsObjects[i].transform.SetParent(cosmeticsInventory);
    77.                 }
    78.             }
    79.  
    80.             Debug.Log("Coins: " + Coins);
    81.             Debug.Log("IsLaserBought: " + IsLaserBought);
    82.             Debug.Log("Current Material: " + CurrentMaterial);
    83.  
    84.  
    85.             fs.Close();
    86.  
    87.  
    88.         }
    89.     }
    90.  
    91.     void Update()
    92.     {
    93.         // FOR THE INSPECTOR
    94.         if (TriggerSave == true)
    95.         {
    96.             SaveMethod();
    97.             TriggerSave = false;
    98.         }
    99.         if (TriggerLoad == true)
    100.         {
    101.             LoadMethod();
    102.             TriggerLoad = false;
    103.         }
    104.     }
    105.  
    106. }
    107.  
    108.  
    But I think I should move it outside of the SaveSystem script, right? Because I don't even save it
     
  40. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522

    you can as long as you dont do it before this
    Code (CSharp):
    1.  isMaterialOwned = sv.Save_isMaterialOwned;
     
  41. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    Then it's better to not move it
     
  42. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    Why you are helping me so much?
     
  43. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    Well I started to help you I might aswell finish than leave you without something you can work with =)
     
  44. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    Do you think that it's better to use playerprefs for things like saving sound settings ?
     
  45. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    its the same, use what you like better
     
  46. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    I can't figure out how to do it :( both doesn't work upload_2020-6-6_13-34-37.png
    upload_2020-6-6_13-35-8.png
     
  47. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
  48. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    i don't know, how whatever
     
  49. brigas

    brigas

    Joined:
    Oct 4, 2014
    Posts:
    522
    just add a new float to the save class, like you have already learned
     
  50. SonGokuBg

    SonGokuBg

    Joined:
    Apr 16, 2020
    Posts:
    146
    Can I set the mixer volume without a slider ?