public Text scoreBoard;
public int score;
public string scoreText;
void Update()
{
scoreText = "Score: " + score.ToString();
scoreBoard.text = scoreText;
}
or
public Text scoreBoard;
public int score;
void Update()
{
string scoreText = "Score: " + score.ToString();
scoreBoard.text = scoreText;
}
Reason: I don’t like to duplicate data (no good reason exists to store the score as BOTH a number AND a string, keep just one). This keeps the save file, and memory footprint, smaller.
Exception: if the computation was more extensive that a simple number to string conversion- some process that required significant time to compute: then it might be worth storing both versions of the data.
Worth noting: by NOT assigning the member the “public” keyword (in example 1), you will be preventing that data from being saved to disk. (Though this would NOT reduce the runtime memory footprint.)