- Home /
Saving state instead of highscore
At first I'd like to apologize for my bad english, I'm form Poland :)
Here is my problem. I have my coin script and the other one, that counts number of how many I collect them in one round and then saves state as highscore. I want it to save state from all rounds like that(like a bank account):
Account = number of coins collected in all previous rounds + number of coins collected in round that I just finished
Here is my script that I'm using for collecting and saving higscore. What I have to do to create account instead of highscore?
using UnityEngine; using System.Collections; using UnityEngine.UI;
public class ScoreSystemCS : MonoBehaviour {
public static int myScore;
public int highScore1;
Text scoreText1;
Text highText1;
public void Start(){
myScore = 0;
highScore1 = PlayerPrefs.GetInt("HighScore1",0);
scoreText1 = GameObject.Find ("scoreText1").GetComponent<Text>();
highText1 = GameObject.Find ("highText1").GetComponent<Text>();
}
public void Update(){
scoreText1.text = ("myScore: " + myScore);
highText1.text = ("Account: " + highScore1);
}
public void CheckHighscore(){
if (myScore > highScore1) {
Debug.Log ("Saving Score");
PlayerPrefs.SetInt ("HighScore", myScore);
}
}
}
Can you explain more, what you are trying to achieve... if you are trying to save total coins collected all over, then that is what you are doing exactly.you are loading the playerprefs in beginning and saving the progress correctly...
Answer by Priyanshu · Mar 22, 2015 at 06:10 AM
Thank you, but actually I don't understand it. I hope that someone here will tell and explain me how to do it :)
Your answer
Follow this Question
Related Questions
Text on Enter Trigger / Text Delay 1 Answer
Distribute terrain in zones 3 Answers
How to create a save & load system with: System.Serializable ??? 1 Answer
Not loading correct Scene/Level 1 Answer
Multiple Cars not working 1 Answer