- Home /
How to keep Highscores?
Hello. I would like my game to be able to keep highscores but I'm not sure how to do so. I have seen some answers concerning that but I don't quite understand. Do I have to use "PlayerPrefs" to keep the score? How do I display it at the end of the game; do I have to create another scene? This is the current score scripts that I'm using.
Attached to GUI text:
static var score : float = 0;
function Update ()
{
guiText.text = "Score : " + score;
}
This is the script to increase the score:
var score = 0;
function OnTriggerEnter (other : Collider)
{
keepscore.score += 25;
gameObject.active = false;
Destroy(gameObject);
}
Thank you for your help.
Answer by AngryMarine · Aug 29, 2011 at 02:51 AM
I would recommend reading up on the System IO functionality of .NET which is available to UnityScript. I attached the link below. You can use it to create a file and store your high scores in, then read it back when you reopen the game and import the data.
Here's a link that helps me figure out System IO.
This link should help Javascript specific questions on Read and Write.
Hello. This is to use a server based highscore? How do I use it in Unity? Thank you.
Nope, it can be used to write local files as you see fit. It should work with server based if that what you'd want to do but I'm not familar with that route myself. Just local stand alone work. It's a bit tough to get into but it'll work for your purposes quite well since you are trying to avoid the PlayerPrefs route.
In fact you could just create the file in windows, place it where you like and then just edit it with system IO. Simple text file should do. ;-)
hahaha local stand alone is sufficient. Just needed a high score board. What kind of file should I create in windows? Possible to explain it a bit more? Simple text file like .doc? Thank you so much!!
I used a simple .txt file. Under the File Class (if I remember right) you can find most of the methods you'll need to edit the file as you need. Like append, etc. A text file is really easy to check too since you can just open it up and check to see if what you were intending happens. I'm no pro so I like to keep it simple. ;-)
I just added a new link to my answer which will help make sense of the System IO and using a simple txt file! I used it myself when I was messing with System IO.
Okay. Is it something like the scores will be written into the .txt file and the game will recall the last high score? I'm a bit confuse. Thank you!
Your answer
Follow this Question
Related Questions
Distance and Best Distance 1 Answer
Reset highScore in Java problem 0 Answers
Highscore Save 0 Answers