public void SaveData() { theHandGun = FindObjectOfType <HandGunController>(); theAutoGun = FindObjectOfType <AutoGunController>(); saveData.handGunBulletCount = theHandGun.currentGunWeapon.currentBulletCount; saveData.autoGunBulletCount = theAutoGun.currentGunWeapon.currentBulletCount; string json = JsonUtility.ToJson(saveData); File.WriteAllText(SAVE_DATA_DIRECTRORY + SAVE_FILENAME, json); Debug.Log("Saved"); Debug.Log(json); }
public void LoadData() { if (File.Exists(SAVE_DATA_DIRECTRORY + SAVE_FILENAME)) { theHandGun = FindObjectOfType <HandGunController>(); theAutoGun = FindObjectOfType <AutoGunController>(); string loadJson = File.ReadAllText(SAVE_DATA_DIRECTRORY + SAVE_FILENAME); saveData = JsonUtility.FromJson <SaveData>(loadJson); theHandGun.currentGunWeapon.currentBulletCount = saveData.handGunBulletCount; theAutoGun.currentGunWeapon.currentBulletCount = saveData.autoGunBulletCount; Debug.Log("Loaded"); } else { Debug.Log("No Saved Data"); } }