Search Unity

ScoreManager problem

Discussion in 'Scripting' started by sonys222, Sep 1, 2015.

  1. sonys222

    sonys222

    Joined:
    Jun 3, 2015
    Posts:
    32
    Hey. I have a problem. Script earlier work, but I wanted to make the levels of the same game and save the high score is not working.

    Code (csharp):
    1. using UnityEngine;
    2. using UnityEngine.UI;
    3. using System.Collections;
    4.  
    5. public class ScoreManagerEasy : MonoBehaviour {
    6.     public static ScoreManagerEasy OG2D;
    7.     public static int score1=0;
    8.     public static int bestWynik1 = 0;
    9.  
    10.  
    11.  
    12.     void start(){      
    13.         OG2D = this;
    14.         bestWynik1 = PlayerPrefs.GetInt ("HighScore1",0);
    15.     }
    16.  
    17.     /*void OnGUI()//
    18.     {
    19.         GUI.color = Color.white;
    20.         GUI.Label (new Rect (10, 30, 100, 20), "HighScre: " + bestWynik);
    21.  
    22.     }*/
    23.  
    24.  
    25.  
    26.     Text text;
    27.  
    28.     void Awake () {
    29.         text = GetComponent <Text> ();
    30.         OG2D = this;//
    31.         score1 = 0;
    32.         bestWynik1 = PlayerPrefs.GetInt ("HighScore1",0); //
    33.  
    34.     }
    35.  
    36.     // Update is called once per frame
    37.     public void Update () {
    38.         text.text = "Score:"+ score1;
    39.     }
    40.  
    41.     public void CheckHighScore() //
    42.     {
    43.         if (score1 > bestWynik1)
    44.         {
    45.  
    46.             Debug.Log ("Saving Score"+bestWynik1);
    47.  
    48.             PlayerPrefs.SetInt("HighScore1",score1);
    49.    
    50.         }
    51.  
    52.     }
    53. }
     
    Last edited: Sep 1, 2015
  2. LeftyRighty

    LeftyRighty

    Joined:
    Nov 2, 2012
    Posts:
    5,148
    please use [code ][/code ] tags when pasting code into the forums, really helps with the readability, there is a sticky on them at the top of the scripting forum.
     
  3. sonys222

    sonys222

    Joined:
    Jun 3, 2015
    Posts:
    32
    Ok. Sorry.
     
  4. sonys222

    sonys222

    Joined:
    Jun 3, 2015
    Posts:
    32
    Nobody know how fix this problem ?
     
  5. Daniel-F-F

    Daniel-F-F

    Joined:
    Apr 7, 2014
    Posts:
    9
    public void CheckHighScore()
    {
    if (score1 > bestWynik1)
    {

    bestWynik1 = score1; // Try add that
    Debug.Log ("Saving Score"+bestWynik1);

    PlayerPrefs.SetInt("HighScore1",score1);

    PlayerPrefs.Save(); // And try add that
    }

    }