Displaying a "Hello World" UI text message
The first traditional problem to be solved with a new computing technology is to display the Hello World message. In this recipe, you'll learn to create a simple UI Text object with this message, in large white text with a selected font, in the center of the screen:

Getting ready
For this recipe, we have prepared the font that you need in a folder named Fonts in the 01_01 folder.
How to do it...
To display aHello Worldtext message, follow these steps:
- Create a new
Unity 2D project. - Import the provided
Fontsfolder. - In the
Hierarchypanel, add aUI|Text GameObjectto the scene—choose menu:GameObject|UI|Text. Name this GameObjectText-hello.
Note
Using the Create menu : Alternatively, use the Create menu immediately below the Hierarchy tab, choosing menu: Create | UI | Text.
- Ensure that your new
Text-helloGameObject is selected in theHierarchypanel. Now, inthe Inspector, ensure the following properties are set:- Text set to read
Hello World - Font set to
Xolonium-Bold - Font size as per your requirements (large—this depends on your screen—try
50or100) - Alignment set to horizontal and vertical center
HorizontalandVertical Overflowset toOverflow- Color set to white
- Text set to read
The following screenshot shows the Inspector panel with these settings:

- In the
Rect Transform, click on theAnchor Presetssquare icon, which should result in several rows and columns of preset position squares appearing. Hold down Shift+Alt and click on the center one (middlerow and center column).
Note
The screenshot of the Rect Transform in the Introduction highlights the middle-center preset needed for this recipe.
- Your
Hello Worldtext will now appear, centered nicely in theGame panel.
How it works...
You have added a new Text-hello GameObject to a scene. A parent Canvas and UI EventSystem will also have been automatically created.
You set the text content and presentation properties and used the Rect Transform anchor presets to ensure that whatever way the screen is resized, the text will stay horizontally and vertically centered.
There's more...
Here are some more details you don't want to miss.
Styling substrings with Rich Text
Each separate UI Text component can have its own color, size, boldness styling, and so on. However, ifyou wish to quickly add some highlighting style to part of a string to be displayed to the user, the following are examples of some of the HTML-style markups that are available without the need to create separate UI Text objects:
- Embolden text with the "b" markup: I am
<b>bold</b> - Italicize text with the "i" markup: I am
<i>italic</i> - Set the text color with hex values or a color name: Iam
<color=green>greentext</color>,butIam<color=#FF0000>red</color>
Note
Learn more from the Unity online manual's Rich Text page at http://docs.unity3d.com/Manual/StyledText.html.