- Home /
Question by
mouhammadbatarni · Aug 04, 2018 at 07:59 PM ·
c#unity 5unity 2dsavegame
My balance in the game and my multiplier are not saving, i cant figure out why, any help?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public static class SaveGameData
{
// Save the game automatically when the player quits
public static void Save()
{
// Save the current system time as a string in the player prefs class
PlayerPrefs.SetString("SaveDateTime", System.DateTime.Now.ToBinary().ToString());
// Save total balance
PlayerPrefs.SetFloat("Balance", GameManager.instance.balance);
PlayerPrefs.SetFloat("allprofitmultiplier", GameManager.instance.allprofitmultiplier);
// Save all stores settings
SaveStores();
// Save all upgrades
SaveUpgrades();
// Update the preference file so we know that game is saved.
PlayerPrefs.SetInt("GameSaved", 1);
}
public static void SaveStores()
{
int counter = 1;
foreach (Store storeObj in GameManager.storeList)
{
PlayerPrefs.SetFloat("storecount_" + counter, storeObj.storeCount);
PlayerPrefs.SetInt("storemultiplier_" + counter, storeObj.storeMultiplier);
PlayerPrefs.SetFloat("storecurrenttimer_" + counter, storeObj.CurrentTimer);
PlayerPrefs.SetInt("storetimer_" + counter, storeObj.storeTimer);
PlayerPrefs.SetFloat("storeprofitmultiplier_" + counter, storeObj.profitmultiplier);
PlayerPrefs.SetFloat("basestoreprice_" + counter, storeObj.baseStorePrice);
int Unlocked = 0;
if (storeObj.hasManager)
{
Unlocked = 1;
}
PlayerPrefs.SetInt("storemanagerunlocked_" + counter, Unlocked);
Unlocked = 0;
if (storeObj.storeUnlocked)
{
Unlocked = 1;
}
PlayerPrefs.SetInt("storeunlocked_" + counter, Unlocked);
counter++;
}
}
public static void SaveUpgrades()
{
int counter = 1;
foreach (Upgrades storeUpgrade in GameManager.storeUpgrades)
{
PlayerPrefs.SetInt("upgradecounter_" + counter, storeUpgrade.upgradeCounter);
counter++;
}
}
}
this is my savedata script, if the problem is not from here tell me so i can show my load game script maybe the problem is there, the only thing that doesnt get saved to my knowledge is balance and allprofitmultiplier.
Comment