- Home /
Question by
domi.r · Jun 30, 2014 at 02:54 PM ·
scorecounterhighscorespoints
Highscore Save
I have write a Script for save the highscore, but it doesn't run. sorry for the German words. thanks for help me !
using UnityEngine; using System.Collections;
public class Counter : MonoBehaviour { public static int points; int oldhighscore; bool gameStarted = false; bool gameFinished = false; public GameObject myPlayer; // Use this for initialization void Start () { GameEventManager.GameStart += spielWurdeGestartet; GameEventManager.GameOver += spielWurdeBeendet; }
// Update is called once per frame
void Update () {
if (gameStarted) {
points++;
guiText.text = "" + points;
} else {
guiText.text = "press ALTGR to start and SPACE to jump";
}
if (gameFinished == true) {
gameStarted = false;
guiText.text = "You reached " + points + " points, press ALTGR to restart";
if (points > oldhighscore) {
PlayerPrefs.SetInt ("highscore", points);
oldhighscore = points;
}
if (Input.GetKeyDown (KeyCode.AltGr)) {
gameStarted = true;
gameFinished = false;
Application.LoadLevel (Application.loadedLevel);
}
}
if (Input.GetKeyDown (KeyCode.AltGr)) {
gameStarted = true;
}
}
public void spielWurdeBeendet() {
gameFinished = true;
}
public void spielWurdeGestartet() {
points = 0;
gameStarted = true;
}
}
Comment