Text object updating on everything else except for variable
The following code seemed simple enough, but I cannot for the life of me figure out why the variable of 'currentScore' is not reflected in the game view. All other aspects of the Text object change, and the variable output in the console (print) of newScoreText does in fact contain any updated score value if present. It goes up as expected there, 5, 10, etc -- and is show as a full text string as it's intended.
Regardless, the value in the string shown on the actual game screen is always still zero. Other aspects of the string can be changed, and are reflected, except for the currentScore variable. Basically the Text object updates, it just stays at "0" where the score value should be presented
What piece am I missing here?
public Text scoreText;
private float currentScore = 0;
void Awake() {
scoreText = GameObject.Find("textScore").GetComponent<Text>();
}
// Update is called once per frame
void Update () {
var newScoreText = "SKOR: " + currentScore.ToString();
print(newScoreText);
scoreText.text = newScoreText;
}
public void IncreaseScore(float increase)
{
currentScore += increase;
}
Because you never change currentScore
value, unless you call IncreaseScore()
from another script.
Good catch -- that's a detail I left out. IncreaseScore is being called from another script. Right now that's happening when an object in the scene is destroyed.
I've proven that's working -- attached is a screenshot of output from the Update() I'm having trouble with. You can see the score -- and string -- changing accordingly, yet in the game view the number never changes from 0.
[1]: /storage/temp/101023-screen-shot-2017-08-31-at-92802-am.png
ins$$anonymous$$d of calling it in Update() you can try this :
public void IncreaseScore(float increase)
{
currentScore += increase;
var newScoreText = "S$$anonymous$$OR: " + currentScore;
print(newScoreText);
ScoreText.text = newScoreText;
}