- Home /
              This question was 
             closed Apr 28, 2020 at 11:53 PM by 
             Juwairia_ for the following reason: 
             
 
            The question is answered, right answer was accepted
I want to save scores and keep incrementing from saved score on restarting the game or in next level/scene?
public class Trig : MonoBehaviour { public int coins; public Text score; public void Start() {
     score.text = PlayerPrefs.GetString("coins").ToString();
}
public void Trt() {
     if (inTrigger)
     {
        
         coins += 1;
        score.text = coins.ToString();
       
     }
public void OnApplicationQuit() { PlayerPrefs.SetString("coins", score.text); PlayerPrefs.Save(); }
 } 
It is just saving the coins and shows but resets on restarting the game or in next scene.
               Comment
              
 
               
               
               Best Answer 
              
 
              Answer by Cassos · Apr 28, 2020 at 07:43 PM
Hope that this helps you cause I don't know if I understood your question propperly:
     // To Save your coins
     PlayerPrefs.SetInt("Coins", coins);
     
     // To get the amount of coins from the last Save
     coins = PlayerPrefs.GetInt("Coins");
Follow this Question
Related Questions
Android Build not deleting PlayerPrefs 1 Answer
Invalid floats in PlayerPrefs 3 Answers
onapplicationquit() function is not working with unity 4.6.3 (android) 3 Answers
PrefabUtility does not exist? 1 Answer
Save Values On Closing of Game 1 Answer
 koobas.hobune.stream
koobas.hobune.stream 
                       
                
                       
			     
			 
                