При создании разработчик, который объясняет принцип сохранения ссылается на List:
public List<Item> shopItems = new List<Item>();
private Save sv = new Save();
sv = JsonUtility.FromJson<Save>(PlayerPrefs.GetString("SV"));
score = sv.score;
for (int i = 0; i < shopItems.Count; i++)
{
shopItems[i].levelOfItem = sv.levelOfItem[i];
shopItems[i].bonusCounter = sv.bonusCounter[i];
if (shopItems[i].needCostMultiplier) shopItems[i].cost *= (int)Mathf.Pow(shopItems[i].costMultiplier, shopItems[i].levelOfItem);
if (shopItems[i].levelOfItem != 0) scoreIncrease += (int)Mathf.Pow(shopItems[i].bonusIncrease, shopItems[i].levelOfItem);
public class Save
{
public int score;
public int[] levelOfItem;
public int[] bonusCounter;
}
В моем же случае мне необходимо сохранить количество очков и "Рабочую силу", которая дает пассивное накопление очков. Мой код :
public int score;
public int bonus = 1;
public int WorkersCount;
public Save SaveGame = new Save();
private void OnApplicationQuit()
{
SaveGame.score = score;
SaveGame.WorkersCount = new int [WorkersCount.Count];
for (int i = 0; i < WorkersCount.Count; i++)
{
SaveGame.WorkersCount[i] = WorkersCount[i].WorkersCount;
}
PlayerPrefs.SetString("GameSave", JsonUtility.ToJson(SaveGame));
}
[Serializable]
public class Save
{
public int score;
public int [] WorkersCount;
}
В мое случае движок на меня ругается :
1. Cannot apply indexing with [] to an expression of type 'int
2.'int' does not contain a definition for 'Count' and no accessible extension method 'Count' accepting a first argument of type 'int' could be found