Hi guys,
im making a 2D endless runner for android and right now i have a problem with the score.
while the game is going on the score is displayed perfectly but when the GAME OVER scene is displayed the score is shown as 0 when its supposed to show the score you got while playing.
I have two scripts handling the scores :
using UnityEngine;
using System.Collections;
public class HUDscript : MonoBehaviour
{
float playerscore = 0f ;
void Update ()
{
playerscore += Time.deltaTime;
}
public void IncreaseScore(int amount)
{
playerscore += amount;
}
void OnDisplay()
{
PlayerPrefs.SetInt("Score", (int)playerscore);
}
void OnGUI()
{
GUI.Label (new Rect (10, 10, 100, 30), "Score: " + (int)(playerscore * 100));
}
}
using UnityEngine;
using System.Collections;
public class GameOverScript : MonoBehaviour
{
int score;
void Start ()
{
score = PlayerPrefs.GetInt ("Score");
}
void OnGUI()
{
GUI.Label (new Rect (Screen.width / 2 - 10, 100, 50, 50), "GAME OVER");
GUI.Label (new Rect (Screen.width / 2 - 30, 300, 80, 30), "Your Score: " + score);
if(GUI.Button(new Rect (Screen.width / 2 - 20, 350, 60, 30), "Retry?"))
{
Application.LoadLevel(0);
}
}
}