Hello, I’ve an problem with my save system.
When you run the game in the unity editor and do some changes in an scriptable object it saves it by it self, but if you build the game and you change something to an scriptable object is won’t save.
But I’ve an Scriptable Object (class inventorycar) and I want it that if you add or remove an item that is save the changes. But I got an problem. Possible somebody can help me with this problem.
Thankyou in advance !
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using UnityEditor;
using UnityEngine;
Class 1:
[System.Serializable]
[CreateAssetMenu(fileName = "Data", menuName = "Inventory/L istCar", order = 1)]
public class InventoryCar : ScriptableObject {
public List<ItemCar> InventoryItem = new List<ItemCar>();
public bool b_mobile = false;
public float mobileMaxSpeedOffset = 0;
public float mobileWheelStearingOffsetReactivity = 0;
public bool b_Countdown = true;
public bool b_LapCounter = true;
public int SavedListCount;
public void SaveList()
{
for (int i = 0; i < InventoryItem.Count; i++)
{
PlayerPrefs.SetString("TotalCars" + i, InventoryItem[i].Cars.());
}
PlayerPrefs.SetInt("Count", InventoryItem.Count);
}
public void LoadList()
{
InventoryItem.Clear();
SavedListCount = PlayerPrefs.GetInt("Count");
for (int i = 0; i < SavedListCount; i++)
{
ItemCar cars = PlayerPrefs.GetString("TotalCars" + i.ToString());
InventoryItem.Add(cars);
}
}
Script 2:
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
[System.Serializable]
public class ItemCar
{
[SerializeField]
public List<GameObject> Cars = new List<GameObject>();
}