void Start() { player = FindObjectOfType <playercontroller>(); player2 = FindObjectOfType <playercontroller_2>(); if (SceneManager.GetActiveScene().buildIndex < 3) { bottleAmount = 0; } else { bottleAmount = PlayerPrefs.GetInt("potion"); } amountText.text = bottleAmount.ToString(); }
public static void SavePlayer(playercontroller_2 player, int levelNumber) { BinaryFormatter formatter = new BinaryFormatter(); string path = Application.persistentDataPath + "/player.fun"; if (File.Exists(path)) { FileStream previousStream = new FileStream(path, FileMode.Open); PlayerData previousData = formatter.Deserialize(previousStream) as PlayerData; previousStream.Close(); if (previousData.level > levelNumber) { return; } File.Delete(path); } FileStream stream = new FileStream(path, FileMode.Create); PlayerData data = new PlayerData(player, levelNumber); formatter.Serialize(stream, data); stream.Close(); }
public PlayerData(playercontroller_2 player, int levelNumber) { coins = player.coinCollectedDisplayer.currentamount; level = levelNumber; }