Question by
LuckierBread · Jul 06, 2016 at 11:11 PM ·
textscorescore system
UI printing in multiple sections.(not supposed to) c#(Solved)
Hey guys, so I am having trouble with my c# script.
What I want to happen Have two UI texts. one to count score while the game plays, one to show the score in the middle of the screen when the game ends,
What is happening The game over score and in-game score are both counting like the in-game is supposed to
I have gone over it multiple times and can't seem to figure out my issue
This is all the relevant script
public Text gameOverScoreText;
public Text scoreText;
public Text highScoreText;
//the gameOver bool is triggerd by a game over event which sets Time.timeScale = 0
private bool gameOver;
void Start ()
{
restartButton.SetActive(false);
gameOverScoreText.text = "";
scoreText.text = "Score: " + 0;
gameOver = false;
}
void Update()
{
if (gameOver == false)
{
score = Time.timeSinceLevelLoad;
scoreText.text = "Score: " + score.ToString("f2");
}
else
scoreText.text = "";
gameOverScoreText.text = "Score: " + score.ToString("f2");
}
Comment
Answer by LuckierBread · Jul 07, 2016 at 09:33 PM
So i figured out what i needed to do in order to make it work.
I replaced the else in the void update function to an if (gameOver == true). However i though that the else statement would have done the same thing.
Can anyone explain to me why else didn't work?