My score is time based. If i pause the game the score just continues adding. Anyone know how to fix?Heres my pause and score scripts.
Score script
public int Score = 0;
public int highScore = 0;
public bool hit;
public GUISkin myskin;
void Start(){
highScore = PlayerPrefs.GetInt ("HighScore",0);
}
void Update(){
Score += (int)Time.time;
}
public void IncreaseScore(int amount)
{
Score += amount;
}
void OnDisable()
{
if (Score > highScore) {
//highScore = playerScore;
PlayerPrefs.SetInt ("HighScore", Score );
PlayerPrefs.Save();
}
PlayerPrefs.SetInt ("Score", (int)Score );
}
void OnGUI()
{
GUI.skin = myskin;
GUI.Label(new Rect(600,50,200,100), "Score:" + (int)(Score));
}
Pause script:
public GUISkin myskin;
public GUISkin my1skin;
public string levelToLoad;
public bool paused = false;
private void Start()
{
Time.timeScale=1; //Set the timeScale back to 1 for Restart option to work
}
private void OnGUI()
{
GUI.skin = myskin;
if (GUI.Button(new Rect(700,10,50,50),"")) //check if Escape key/Back key is pressed
{
if (paused){
paused = false;
//unpause the game if already paused
}else{
paused = true;//pause the game if not paused
}
if(paused){
Time.timeScale = 0; //set the timeScale to 0 so that all the procedings are halted
}else{
Time.timeScale = 1; //set it back to 1 on unpausing the game
}
}
GUI.skin = my1skin;
if (paused){
GUI.Box(new Rect(Screen.width/4, Screen.height/4, Screen.width/2, Screen.height/2), "PAUSED");
//GUI.Label(new Rect(Screen.width/4+10, Screen.height/4+Screen.height/10+10, Screen.width/2-20, Screen.height/10), "YOUR SCORE: "+ ((int)score));
if (GUI.Button(new Rect(Screen.width/4+10, Screen.height/4+Screen.height/10+10, Screen.width/2-20, Screen.height/10), "RESUME")){
paused = false;
Time.timeScale = 1;
}
if (GUI.Button(new Rect(Screen.width/4+10, Screen.height/4+2*Screen.height/10+10, Screen.width/2-20, Screen.height/10), "RESTART")){
Application.LoadLevel(Application.loadedLevel);
}
if (GUI.Button(new Rect(Screen.width/4+10, Screen.height/4+3*Screen.height/10+10, Screen.width/2-20, Screen.height/10), "MAIN MENU")){
Application.LoadLevel("-main menu");
}
}
}