Unity Saving Scores

Posts 17 of 7 · Page 1 of 1
Unity Saving Scores
Hello Guys! I am making a game in unity C# and I want to save previous scores in a txt file and be able to reference them. The key is getting them to stay after I close and re-open the game. I have heard you can acomplish this by storing it in a txt file. anyone know how? Thanks in advance.
Are you looking for something in the Unity framework geared towards text files, or plain c#?
Quote Originally Posted by abuckau907 View Post
Are you looking for something in the Unity framework geared towards text files, or plain c#?
Unity framework or C#, Either works
If you want to save it in txt, so use StreamWriter and StreamReader.
Quote Originally Posted by Chhaos. View Post
If you want to save it in txt, so use StreamWriter and StreamReader.
Thanks, ended up figuring this out.
you could do something like
Code:
public int score;
then when you finish the level, say you have an object that you need to hit to finish the level you could do,

Code:
void OnTriggerEnter(Collider c){

if(c.gameobject.tag == "Finish"){
playerprefs.setInt("Score",score);
}

}
and then for loading it back up you can just do
Code:
void Awake(){
score = playerprefs.getInt("Score",score);

}
this is the way i do it when im making my games, Hope this helps, you may need to fix the capitalization of the letters
Posts 17 of 7 · Page 1 of 1

Post a Reply

Similar Threads

Tags for this Thread

None

Need help?