
上QQ阅读APP看书,第一时间看更新
How to do it...
To display a Hello World text message, follow these steps:
- Create a new Unity 2D project.
- Import the provided Fonts folder.
- In the Hierarchy panel, add a UI | Text GameObject to the scene—choose menu: GameObject | UI | Text. Name this GameObject Text-hello.
Using the Create menu : Alternatively, use the Create menu immediately below the Hierarchy tab, choosing menu: Create | UI | Text.
- Ensure that your new Text-hello GameObject is selected in the Hierarchy panel.
Now, in the 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 50 or 100)
- Alignment set to horizontal and vertical center
- Horizontal and Vertical Overflow set to Overflow
- Color set to white
The following screenshot shows the Inspector panel with these settings:
- In the Rect Transform, click on the Anchor Presets square 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).
The screenshot of the Rect Transform in the Introduction highlights the middle-center preset needed for this recipe.
- Your Hello World text will now appear, centered nicely in the Game panel.