Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

using highscore in next scene

Discussion in 'Scripting' started by JohnDmu, Apr 26, 2015.

  1. JohnDmu

    JohnDmu

    Joined:
    Apr 8, 2015
    Posts:
    33
    hello people..!
    i have a guitext having a script like ..
    Code (CSharp):
    1. static int score = 0;
    2.  
    3.     static int highScore = 0;
    4.     static public void AddPoint() {
    5.                 score ++;
    6.    
    7.                 if (score > highScore) {
    8.                         highScore = score;
    9.  
    10.                 }
    11.         }
    12.     void Start()
    13.     {
    14.  
    15.         score = 0;
    16.         highScore = PlayerPrefs.GetInt ("highScore", 0);
    17.  
    18.  
    19.     }
    20.  
    21.     void OnDestroy()
    22.     {
    23.  
    24.         PlayerPrefs.SetInt ("highScore", highScore);
    25.  
    26.  
    27.         }
    28.  
    29.     void Update()
    30.     {
    31.  
    32.         guiText.text = " " + score + "\nHigh Score: " + highScore;
    33.    
    34. }
    35. }

    my first problem is that i want to take those two values (score, highscore)
    and use them in my retry/gameover scene!
    HOW CAN I DO THAT??

    the second problem is that im trying to find a way to make guitext resolution independent and i cant find..
    any suggestions??

    thanks in advance!
     
  2. hamsterbytedev

    hamsterbytedev

    Joined:
    Dec 9, 2014
    Posts:
    353
    Seems you already know how to use PlayerPrefs, so why can't you use these scores in your next scene?
     
  3. JohnDmu

    JohnDmu

    Joined:
    Apr 8, 2015
    Posts:
    33
    i used playerprefs to save my highscore!
    how can i use on the next screen though?
    im reading the manual and coding!
    not some serious level of coding!
     
  4. hamsterbytedev

    hamsterbytedev

    Joined:
    Dec 9, 2014
    Posts:
    353
    assign the text parameter of your text component to PlayerPrefs.GetInt("highscore"); When you save a value in playerprefs it is always there you just have to assign it somewhere to see it

    myText.text = PlayerPrefs.GetInt("highscore").ToString();

    similar to that.
     
    Last edited: Apr 26, 2015
  5. JohnDmu

    JohnDmu

    Joined:
    Apr 8, 2015
    Posts:
    33
    i understood thank you very much..!
    according to the resolution independent gui text??
    any suggestions??
     
  6. hamsterbytedev

    hamsterbytedev

    Joined:
    Dec 9, 2014
    Posts:
    353
    There are some settings that you will have to play with. Look into the text ui component in the unity docs. You'll need to set a max font size and min font size and set up some anchors for scaling. It's not very difficult and requires no code.
     
  7. JohnDmu

    JohnDmu

    Joined:
    Apr 8, 2015
    Posts:
    33
    ok i ll give it a try have a nice day ! appreciate your help!
     
  8. hamsterbytedev

    hamsterbytedev

    Joined:
    Dec 9, 2014
    Posts:
    353
    No worries. Best of luck! If you need any more help, just ask. The community is very helpful here