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

problem with score counting

Discussion in 'Scripting' started by PhenoMMM, Oct 9, 2020.

  1. PhenoMMM

    PhenoMMM

    Joined:
    Jul 18, 2015
    Posts:
    4
    hello there Im new in unity and I have a "simple" problem....
    all I want here is if the highscore is between 0-40 to show me Scene2, and if the highscore is 41-60 to show me Scene3 and so on....thanks

    Code (CSharp):
    1.  
    2.  
    3. public class Showresult : MonoBehaviour
    4. {
    5.  
    6.     public Text highscore;
    7.  
    8.     void Awake()
    9.     {
    10.  
    11.         highscore.text = PlayerPrefs.GetFloat("CoinsCollected").ToString();
    12.  
    13.         if (PlayerPrefs.GetFloat("CoinsCollected") >= 0 && PlayerPrefs.GetFloat("CoinsCollected") <= 40)
    14.             {
    15.             SceneManager.LoadScene(2);
    16.         }
    17.         else if (PlayerPrefs.GetFloat("CoinsCollected") >= 41 && PlayerPrefs.GetFloat("CoinsCollected") <= 60)
    18.         {
    19.             SceneManager.LoadScene(3);
    20.         }
    21.         else if (PlayerPrefs.GetFloat("CoinsCollected") >= 61 && PlayerPrefs.GetFloat("CoinsCollected") <= 200)
    22.         {
    23.             SceneManager.LoadScene(4);
    24.         }
    25.         return;
    26.     }
    27.  
    28. }
     
  2. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,833
    That's a bit messy but I don't see anything obviously wrong. What actually happens when you run the code?
     
  3. PhenoMMM

    PhenoMMM

    Joined:
    Jul 18, 2015
    Posts:
    4
    It doesnt show me the right scenes... like when its "highscore=50" it still shows me the Scene2 "wrong scene"
     
  4. Antistone

    Antistone

    Joined:
    Feb 22, 2014
    Posts:
    2,833
    Under File -> Build Settings, are you including all the right scenes in the right order? Remember that the first scene in the list is actually #0, so #2 would be the third one in the list, #3 would be the fourth one, etc.

    You can load scenes by name instead of by number if that's easier.
     
  5. PhenoMMM

    PhenoMMM

    Joined:
    Jul 18, 2015
    Posts:
    4
    yeah everything is alright there its just the code....
     
  6. PhenoMMM

    PhenoMMM

    Joined:
    Jul 18, 2015
    Posts:
    4
    ohhh i figured it out my score system wasnt working propertly, and it was getting the old playerprefs... thanks again for your help dude