So I'm trying to use playerprefs for basic score for several levels, options and so on, which has been working really well. However I'm having strange behavior when trying to do a basic int for lives. Here are the scripts. Code (CSharp): using UnityEngine; using System.Collections; using UnityEngine.SceneManagement; public class PlayerPrefsManager : MonoBehaviour { const string MASTER_VOLUME_KEY = "master_volume"; const string HIGH_SCORE1 = "High Score1"; const string HIGH_SCORE2 = "High Score2"; const string HIGH_SCORE3 = "High Score3"; const string HIGH_SCORE4 = "High Score4"; const string SQUISH_LIVES = "Squish Lives"; public static void SetMasterVolume(float volume) { if (volume >= 0f && volume <= 1f) { PlayerPrefs.SetFloat("master_volume", volume); } else { Debug.LogError("Master Volume out of range"); } } public static float GetMasterVolume() { return PlayerPrefs.GetFloat(MASTER_VOLUME_KEY); } public static void SetLives(int lives) { PlayerPrefs.SetInt(SQUISH_LIVES, lives); } public static int GetLives() { return PlayerPrefs.GetInt(SQUISH_LIVES); } public static void SetHighScore(int score) { PlayerPrefs.SetInt(HIGH_SCORE1, score); } public static int GetHighScore() { return PlayerPrefs.GetInt(HIGH_SCORE1); } public static void SetHighScore2(int score) { PlayerPrefs.SetInt(HIGH_SCORE2, score); } public static int GetHighScore2() { return PlayerPrefs.GetInt(HIGH_SCORE2); } public static void SetHighScore3(int score) { PlayerPrefs.SetInt(HIGH_SCORE3, score); } public static int GetHighScore3() { return PlayerPrefs.GetInt(HIGH_SCORE3); } public static void SetHighScore4(int score) { PlayerPrefs.SetInt(HIGH_SCORE4, score); } public static int GetHighScore4() { return PlayerPrefs.GetInt(HIGH_SCORE4); } } Then here is the LivesManager script i thought about using to subtract from lives in the gamemanager script im using, and setting the int and gettting the int. Code (CSharp): using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class LivesManager : MonoBehaviour { private bool isOver = false; public Text livesText; // Use this for initialization void Start () { isOver = false; PlayerPrefsManager.GetLives(); livesText.text = "x" + PlayerPrefsManager.GetLives(); } // Update is called once per frame void Update () { if (GameController.instance.gameOver == true && !isOver) { LivesCounter(); } } void LivesCounter() { GameController.instance.lives--; PlayerPrefsManager.SetLives(GameController.instance.lives); isOver = true; } } I'm basically trying to subtract from the lives count till the player runs out of lives, then if the player wishes to continue playing they have to play a reward ad to get more lives. But its not keeping track of the lives count the way it is suppose to which is odd.
In your LivesManager.Start method, you are not setting lives variable.. only getting it, but not storing it.. you need: GameController.instance.lives = PlayerPrefsManager.GetLives();