- Home /
Creating High score using GUIText, '>' operation no working
All my game texts are GUIText and i'm trying to create a high score to display after each game ends. Every time i try to make an 'if' statement for when the score is higher than the highscore to change the highscore to that score, it either tells me you can't use '>' with GUIText or strings. here's the end of my script where this is occuring, let me know if you need to see more script:
public void AddScore(int newScoreValue)
{
score += newScoreValue;
UpdateScore();
}
void UpdateScore()
{
scoreText.text = "Score: " + score;
}
public void GameOver()
{
gameOverText.text = "Game Over!";
gameOver = true;
highscoreText.text = scoreText.text;
if (scoreText > highscoreText) //this is where the problem is but there may be more issues
{
highscoreText.text = scoreText.text;
}
}
Answer by Nomenokes · Dec 16, 2017 at 05:02 PM
Yep, that's a programming thing. You can't compare strings to each other. (For example, is Nomenokes>Costawong? It doesn't make any sense). You have to compare the actual scores.
if (score > highscore)
{
highscoreText.text = scoreText.text;
}
You may also want to get rid of line 16: highscoreText.text = scoreText.text;
If you don't have a highscore
int variable, you should make one.
-Nomenokes
Thank you, this helped a lot. I still have to get it to remember the last score so it knows how to update it but this was very helpful
Your answer
Follow this Question
Related Questions
Check current letter in typewriter textbox? 0 Answers
Texts As Objects? 1 Answer
How to set different alignments to differenent lines of text in one field of text 0 Answers
String.Remove not working 1 Answer
Why isn't my high score sticking? 2 Answers