Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

how to get high score with "double" variable?

Discussion in 'Scripting' started by athgen113, Aug 16, 2018.

  1. athgen113

    athgen113

    Joined:
    May 25, 2018
    Posts:
    46
    my score is double how to get high score .? with setInt?
    Code (CSharp):
    1.  
    2.  
    3.  [SerializeField] Text scoreText, highScoreText;
    4.     private double currentScore,highscore;
    5. private void Awake()
    6.     {
    7.         currentScore = GameManager.Instance.TotalScore;
    8.         scoreText.text = currentScore.ToString();
    9.         //int convert = (int)currentScore;
    10.         //int highScore = PlayerPrefs.GetInt("highScore", 0);
    11.         //if (convert > highScore)
    12.         //{
    13.         //    PlayerPrefs.SetInt("highScore",currentScore);
    14.         //}
    15.         //highScoreText.text = PlayerPrefs.GetInt("highScore", 0).ToString();
    16.      
    17.         string convert = highscore.ToString();
    18.         PlayerPrefs.GetString("concac", convert);
    19.         string convertscore = currentScore.ToString();
    20.         if (currentScore > highscore)
    21.         {
    22.             PlayerPrefs.SetString("concac", convertscore);
    23.         }
    24.         highScoreText.text = PlayerPrefs.GetString("concac",convertscore).ToString();
    25.     }
     
  2. athgen113

    athgen113

    Joined:
    May 25, 2018
    Posts:
    46
  3. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    Hi athgen113,

    Is there any particular reason that your score is a double?

    If your score were an int, the you could just use GetInt and SetInt on PlayerPrefs to save and load your score.

    If you really want more precision in your score, you could make the score be a
    float
    . Then you could use GetFloat and SetFloat. A float is very similar to a double but a double just has more bits so can store more values to a higher accuracy.
     
  4. athgen113

    athgen113

    Joined:
    May 25, 2018
    Posts:
    46
    i only use double so what can i do
     
  5. Doug_B

    Doug_B

    Joined:
    Jun 4, 2017
    Posts:
    1,596
    You can use GetFloat / SetFloat. It is most likely that will be fine.

    But I am curious - why are you using double?