public void LoadGame() { if (File.Exists(Application.persistentDataPath + "/playerData.dat")) { BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/playerData.dat", FileMode.Open); PlayerData data = (PlayerData)bf.Deserialize(file); file.Close(); doOnce = data.doOnce; showTutorials = data.showTutorials; currendCredits = data.currendCredits; HightScore = data.HightScore; LevelProgress = data.LevelProgress; PlayerFirstWeapon = ObjectHolder._PlayerWeapons[ObjectHolder.GetPlayerWeaponIndex((WeaponBehaviourScript.WeaponTypes)data.playerFirstWeaponInt)]; PlayerSecondWeapon = ObjectHolder._PlayerWeapons[ObjectHolder.GetPlayerWeaponIndex((WeaponBehaviourScript.WeaponTypes)data.playerSecondWeaponInt)]; MainMenuControllerScript.NewWeaponPrice = data.NewWeaponPrice; bool[] _unlockedWeapons = data.UnlockedWeapons; UnlockedlvlXWeapons = data.UnlockedlvlXWeapons; for (int i = 0; i < ObjectHolder._PlayerWeapons.Length; i++) { ObjectHolder._PlayerWeapons[i].GetComponent <WeaponBehaviourScript>().isBought = _unlockedWeapons[i]; } } Debug.Log("Game was loaded"); }
void Start() { LoadGame(); //assing stuff if it's still null if (mainCamera == null) { mainCamera = Camera.main; } //inistikasdlize timer scoreTimer.Elapsed += new ElapsedEventHandler(OnScoreTimerTick); scoreTimer.Interval = scoreIntervall; scoreTimer.Start(); currendScore = 0f; //Assinging Player Weapons if needed if (PlayerFirstWeapon == null) { PlayerFirstWeapon = ObjectHolder._PlayerWeapons[ObjectHolder.GetPlayerWeaponIndex(WeaponBehaviourScript.WeaponTypes.Blaster_lvl_1)]; } if (PlayerSecondWeapon == null) { PlayerSecondWeapon = ObjectHolder._PlayerWeapons[ObjectHolder.GetPlayerWeaponIndex(WeaponBehaviourScript.WeaponTypes.Shotgun_lvl_1)]; } //Only for testing weapons if (toAssingFirstWep != null) { PlayerFirstWeapon = toAssingFirstWep; } if (toAssingSecondWep != null) { PlayerSecondWeapon = toAssingSecondWep; } //Instantiate stuff based on the scene bool b = false; foreach (Transform t in transform) { if (t.CompareTag("Stars")) { b = true; } } if (b == false) { StarsInstance = Instantiate(StarsGo, transform); } if (SceneManager.GetActiveScene().name != "Main Menu") { if (GameObject.FindGameObjectWithTag("Player") == null) { Debug.Log("Spawned Player"); PlayerInstance = Instantiate(ObjectHolder._PlayerShips[ObjectHolder.GetPlayerShipIndex(PlayerBehaviourScript.Ships.Standart)]); if (CursorGUIGo != null) { CursorGUIInstance = Instantiate(CursorGUIGo, new Vector3(Camera.main.ScreenToWorldPoint(Input.mousePosition).x, Camera.main.ScreenToWorldPoint(Input.mousePosition).y, 0), Quaternion.identity); Cursor.visible = false; } } } else { Cursor.visible = true; } if (doOnce == true) { doOnce = false; Debug.Log("doing once"); //currendCredits += 10000f; //Sets all Weapons.isBought to false exept for a few selected ones foreach (GameObject playerWeapon in ObjectHolder._PlayerWeapons) { switch (playerWeapon.GetComponent <WeaponBehaviourScript>().WeaponType) { case WeaponBehaviourScript.WeaponTypes.Blaster_lvl_1: playerWeapon.GetComponent <WeaponBehaviourScript>().isBought = true; break; case WeaponBehaviourScript.WeaponTypes.Shotgun_lvl_1: playerWeapon.GetComponent <WeaponBehaviourScript>().isBought = true; break; default: playerWeapon.GetComponent <WeaponBehaviourScript>().isBought = false; break; } } } }