Hello,
I’m here, once again, to ask for help.
I’m working on a local highscore for a game that I’m working on, but after spending the last few hours searching for a good solution, without any luck, i decided to ask.
The curent code that i got for the highscore script is the following:
//Linking the text that needs to show the highscore
public Text highscore;
//If the score is better than the old highscore it needs to be replaced
if (score > PlayerPrefs.GetInt ("highscore")) {
PlayerPrefs.SetInt ("highscore", score);
}
// Get the highscore
highscore = PlayerPrefs.GetInt ("highscore");
//Set the text of the text.
highscore.text = "Highscore: " + highscore;
My issue is:
Cannot implicitly convert type ‘int’ to ‘UnityEngine.UI.Text’
And it leads to this line with the error:
highscore = PlayerPrefs.GetInt (“highscore”);
Is there any way to solve this issue, or maybe another way to make a local highscore?
Thanks.
Regards.
Tech.
My full code:
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
public class EndGameScore : MonoBehaviour {
public Text Finalscore;
public Text highscore;
int score = 0;
// Use this for initialization
void Start () {
if (score > PlayerPrefs.GetInt ("highscore")) {
PlayerPrefs.SetInt ("highscore", score);
}
highscore = PlayerPrefs.GetInt ("highscore");
score = PlayerPrefs.GetInt ("Score");
Finalscore.text = "Your score: " + score;
highscore.text = "Highscore: " + highscore;
}