public static void Load(string playerName) { string path = playerName + "/savegame.dat"; if (File.Exists(Application.persistentDataPath + path)) { CharacterStats charSt = FindObjectOfType <CharacterStats>(); Debug.Log("Load"); BinaryFormatter bf = new BinaryFormatter(); FileStream file = File.Open(Application.persistentDataPath + "/" + playerName + "savegame.dat", FileMode.Open); CharacterData data = (CharacterData)bf.Deserialize(file); file.Close(); //TODO : Lataa arvot ScoreTable.currentPlayer = data.name; ScoreTable.SetScore(ScoreTable.currentPlayer, "score", data.score); CharacterStats.currentCharacterLevel = data.cCharLevel; CharacterStats.levelPojo = data.lPojo; CharacterStats.strength = data.str; CharacterStats.dexterity = data.dex; CharacterStats.vitality = data.vit; CharacterStats.energy = data.ene; charSt.maxHealth = data.mHealth; charSt.maxMana = data.mMana; charSt.replenishH = data.rHealth; charSt.replenishM = data.rMana; charSt.moveSpeed = data.fMoveSpeed; charSt.rotationSpeed = data.rotSpeed; charSt.BackwardsMoveSpeed = data.bMoveSpeed; charSt.jumpForce = data.jForce; Level1 = data._Level1; Level2 = data._Level2; Level3 = data._Level3; Level4 = data._Level4; Level5 = data._Level5; WeaponSwitch wep = FindObjectOfType <WeaponSwitch>(); wep.SwitchToThisWep(0); FindObjectOfType <Axe>().LoadAxeStats(); wep.SwitchToThisWep(1); FindObjectOfType <Sword>().LoadSwordStats(); wep.SwitchToThisWep(2); FindObjectOfType <Spell>().LoadSpellStats(); } }
public void UpdateXp(int exp) { currentCharacterXP += exp; int lvl = (int)(0.1f * Mathf.Sqrt(currentCharacterXP)); if (lvl != currentCharacterLevel) { currentCharacterLevel = lvl; ScoreTable.SetScore(ScoreTable.currentPlayer, "level", currentCharacterLevel); Destroy(Instantiate(lvlUpEff, transform.position, Quaternion.identity), 3f); LevelUpBonus(); } int xpToNext = 100 * (currentCharacterLevel + 1) * (currentCharacterLevel + 1); int difXp = xpToNext - currentCharacterXP; int totalDif = xpToNext - (100 * currentCharacterLevel * currentCharacterLevel); }
public void StartGame() { if (textField.text.Length > 0 && !PlayerPrefs.HasKey(textField.text)) { GameStatus.gameBegin = true; PlayerPrefs.SetString(textField.text, textField.text); PlayerPrefs.SetInt(textField.text + "levels", 1); PlayerPrefs.SetInt(textField.text + "scores", 0); //testing ways to do highscore ScoreTable.SetScore(textField.text, "level", 1); ScoreTable.SetScore(textField.text, "score", 0); ScoreTable.currentPlayer = textField.text; ScoreTable.SaveScores(); Debug.Log("New Challenger! Name: " + textField.text + " Level: " + ScoreTable.GetScore(textField.text, "level") + ", Score: " + ScoreTable.GetScore(textField.text, "score")); SceneManager.LoadScene("Map"); } else if (PlayerPrefs.HasKey(textField.text)) { ScoreTable.currentPlayer = textField.text; Debug.Log(PlayerPrefs.GetString(textField.text)); ScoreTable.LoadScores(); SceneManager.LoadScene("Map"); } }