Unity c# how to add the current score into total score and save it via playerprefs and the current score will back to zero?
public Text scoretxt,anotherscore,bestscore;
public Text startxt,anotherstarTxt;
public static int scoreToadd = 0;
public static int totalscore = 0;
public static int anotherscoreToAdd = 0;
public GameObject balldestory,New;
// Use this for initialization
void Start () {
scoreToadd = 0;
totalscore = PlayerPrefs.GetInt ("score1");
}
// Update is called once per frame
void Update () {
//PlayerPrefs.DeleteAll ();
PlayerPrefs.SetInt ("score1",totalscore);
anotherscoreToAdd = scoreToadd;
anotherscore.text = "" + anotherscoreToAdd;
}
void OnTriggerEnter(Collider hop){
if (hop.gameObject.tag == "Player") {
ss.hooping.Play ();
ss.points.Play ();
balldestory.SetActive (false);
scoreAdd ();
}
}
void scoreAdd(){
scoreToadd ++;
scoretxt.text = "" + scoreToadd;
anotherscore.text = "" + anotherscoreToAdd;
anotherscoreToAdd = scoreToadd;
bestscore.text = "" + PlayerPrefs.GetInt ("score1",totalscore + anotherscoreToAdd);
}
Comment
Your answer
Follow this Question
Related Questions
Help with Pause Menu 1 Answer
Advice on creating 2d Inventory System with Unity 0 Answers
iron sight using inverse kinematic 0 Answers
Why isn't my object lerping ? C# 2 Answers