Did a high score through tutorial on unity 2d for andriod, works on my computer but on mobile devices it doesnt

every block spawn score increases by own
heres the code \

    private void SpawnBLOCK()
    {
        Vector3 spawnPos = spawnpoint.position;
        spawnPos.x = Random.Range(-maxX, maxX);
        Instantiate( block, spawnPos, Quaternion.identity );

        
            score++;
            scoreText.text = score.ToString();

        PlayerPrefs.SetInt("HighScore", score);
        PlayerPrefs.GetInt("Highscore");
    }
    void CheckHighscore()
    {
        if (score > PlayerPrefs.GetInt("Highscore" , 0))
        {
            PlayerPrefs.SetInt("Highscore", score);
           
        }
    }
    void updateHighscoretext()
    {
        highscoretext.text = $"HI - SCORE: {PlayerPrefs.GetInt("HighScore", 0)}";
    }
}

How is it failing?

every block spawn score increases by own

This is the problem? If so, you increment score score++; on line #8.

I’m not seeing a reason for it to specifically fail on mobile, so maybe you could describe the issue in more detail.

i messed up the code. Changed few things, it works fine now.

Please only use tags that relate to the question. That way, your post appears in the correct area. FYI: This is a scripting question and not a 2D-Graphics question because it’s not related to 2D features.

I’ll update the tags for you.

Thanks.

1 Like