// Start is called before the first frame update void Start() { InitGun(); weaponTransform = transform.parent.gameObject.GetComponent <Transform>(); notAimTarget = GameObject.FindGameObjectWithTag("NotAimTarget3_2").GetComponent <Transform>(); audioSource = GetComponent <AudioSource>(); weaponOut = GameObject.FindGameObjectWithTag("WeaponOut").GetComponent <Transform>(); HandGun1 = GameObject.FindGameObjectWithTag("HandGun").GetComponent <HandGunController>(); }
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"); } }