Hello!
I work on a very small project in which a Score [UIText element] is displayed. Whenever a player reaches a certain Score a text should be displayed. [Again with a UIText element]. In this text element i have some lines like “Well Done”, “Keep on Going”, “Almost there!”. So far it works quite well. Once a goalScore is reached the score vanishes for a moment and the message is displayed. After the next shot the text message vanishes and the regular score is displayed again.
The Score.cs script-snippet:
void Update ()
{
GetComponent<GUIText>().text = "Score: " + score;
if (goalScore.Equals(10000))
GetComponent<GUIText>().text = "Well Done!";
if (goalScore.Equals(15000))
GetComponent<GUIText>().text = "Bow Your Head!";
goalScore = score;
}
Although it does what it should there must certainly be a better and more elegant way to solve this. All i want to do is to retrieve predefined messages from the UIText element upon reaching goalScore[1], [2], [3] … without writing dozens of (probably) unnecessary lines of code.
As i am rather new to C# scripting and Unity i hope you’ll explain things a little more in depth in case you provide code examples. Links to the documentation so i can learn and figure things out myself would also be much appreciated!