Time for action – displaying high score values
We haven't done anything complicated with GUI Text
objects, but they can be powerful and versatile with the proper formatting, so now we'll go over a few tricks you can use to cleanly display three different scores in a list format using only one GUI Text
object. Perform the following steps to display high score values:
Attach your
HighScoreText
script to yourGUI Text
object by clicking-and-dragging it over theGUI Text
object in the Hierarchy window.Create a new function called
DisplayHighScores
in theHighScoreText
script as shown:void DisplayHighScores() { }
By default, a
GUI Text
object displays information in a straight line of text, but what we want is something similar to a list. To achieve this, we'll use what's called an escape character or a special character in the middle of a string that dictates how it's processed or displayed. In this case, we'll be using\n
, which creates a new line whenever it's called. While escape characters...