0
public class ArcadeScore : MonoBehaviour {

    public int score, cs;

    ScoreInMenu sm;

    void Start()
    {
        sm = gameObject.AddComponent<ScoreInMenu>();
        cs = sm.arc;
        score = 0;
        Debug.Log(cs);
    }

    void Update() {
        if (score > cs) {
            PlayerPrefs.SetInt("arcadeHighscore", score);
            PlayerPrefs.Save();
        }
    }
}

I have the following code which is supposed to take the latest value and check if the current score is bigger than the highscore

public class ScoreInMenu : MonoBehaviour
{

    public Text scoreText;
    public int arc, tim;

    // Update is called once per frame
    void Start()
    {
        arc = PlayerPrefs.GetInt("arcadeHighscore");
        tim = PlayerPrefs.GetInt("timedHighscore");
        Debug.Log(arc);
        Debug.Log(tim);
        scoreText.text = "ARCADE: " + arc.ToString() + "\n" + "TIMED:    " + tim; //the place where I get the exception
    }
}

and this is the script I use to display the score in the menu, but I receive a Nullreferenceexception where I try to set the text, although when I print the values, they are not null.

Edward
  • 3
  • 1
  • 4

0 Answers0