# Create UI-Text GameObject

To create a Text GameObject, see image below:  **select GameObject > UI > Text**

![](https://1118975008-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0-KLgOacVpbicrqehO%2F-MFCSpX4SE6jXMJFAL4Y%2F-MFCT-Qua_f6daNhq5AS%2FScreen%20Shot%202020-08-20%20at%201.24.53%20PM.png?alt=media\&token=b32752d8-df9d-4d65-af83-a4675c7475ce)

### UI-Text, Canvas, EventSystem

In the image below you can see that 3 new gameObjects are always created when you add the first UI GameObject to a scene: **Canvas, EventSystem, and the Text** that we'd added..  In addition, you can also see there's an offset rectangle positioned at the center of the Scene.  This Rectangle is the Canvas GameObject.  In Unity, by default, the Canvas is offset from the Main Camera, this can be useful in many situations, but for this course, we'll keep things simple, we'll modify the Canvas so that it directly overlays the viewport of the Main Camera.&#x20;

All **UI gameObjects must** always be **children of a Canvas gameObject**.  The **Canvas** and **all UI game Objects** use the **RectTransform**, which means that resizing or moving a parent UI gameObject will cause the child-GameObject to be modified depending on the settings of the Rect-Transform.  The **RectTransform has auto-presets** that make it easy to set the **width, height, and anchoring of UI-elements** relative to it's Parent GameObject.

The **EventSystem** is required in order for the UI elements to be interactive. We won't directly modify the EventSystem, but be aware...if it is not in the Hierarchy, then none of the UI elements will be interactive.  In that case, you can just re-add it as a gameObject

![](https://1118975008-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0-KLgOacVpbicrqehO%2F-MFC5fCTH3c_GxN4k7Gd%2F-MFC6vuzKbDVBJxWYfzi%2FScreen%20Shot%202020-08-20%20at%201.26.46%20PM.png?alt=media\&token=887cc19c-4d83-4007-80b9-6cacbe3af222)

### Configure Canvas Mode:  Screen-Space Camera

[**See Unity Manual**](https://docs.unity3d.com/2020.1/Documentation/Manual/UICanvas.html)\
When the Canvas is added to a scene, the layout is offset from the main camera, this is called **Render Mode: Screen Space-Overlay**. For our purposes, it is easiest to configure the Canvas Component so that it's rendered in the same position as the regular game scene. To do that, we need to change the **Render-Mode** of the **Canvas Component** by selecting the Canvas in the **Hierarchy Panel** and then making changes in the **Inspector panel.** **Change it Canvas Render Mode** from Screen-Space Overlay to **Screen Space - Camera.** Then it's necessary to **select the Main Camera as the Render Camera** for the Canvas Component.&#x20;

See images to configure the **Render Mode of the Canvas to be Screen-Space Camera,** with the **Render Mode set to Main Camera** following the instructional text in the image captions below.

![Select the Canvas in the Hierarchy,  change the Render Mode, default is Screen-Space Overlay](https://1118975008-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0-KLgOacVpbicrqehO%2F-MFCBEQnlyMx5toOlfuo%2F-MFCEKEtpAotwyB7E5Jm%2FScreen%20Shot%202020-08-20%20at%201.46.25%20PM.png?alt=media\&token=449d959c-ef71-4ecf-84a9-0403e883afec)

![Switch RenderMode to ScreenSpace Camera, select the small circle to set the Render Camera.](https://1118975008-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0-KLgOacVpbicrqehO%2F-MFCEMEWN7Lm5f-JV_Qr%2F-MFCS3byoLqCJrrd1IId%2FScreen%20Shot%202020-08-20%20at%201.47.26%20PM.png?alt=media\&token=7fc02f0c-d4ce-4656-b803-9efeec6a5807)

![It may be necessary to switch to the Scene Tab in the Popup window to select Main Camera](https://1118975008-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0-KLgOacVpbicrqehO%2F-MFCEMEWN7Lm5f-JV_Qr%2F-MFCSUcOVFTwxmZeujSL%2FScreen%20Shot%202020-08-20%20at%201.47.36%20PM.png?alt=media\&token=c393ac65-b89b-4e3f-85fa-07ade60990ce)

### Modify the Text Component's text attributes

Finally, select the Text GameObject, rename the gameObject to StudentName.  Then in the Inspector panel you'll need to modify the color, font-size and text attributes so it displays your name.  You can adjust You might need to make the text box larger using the RectTransform tool in the upper left of the UnityEditor.  You can double-click on any GameObject to have it centered in the Scene view. &#x20;

### Set Rect-Transform to Center the Text in the Scene View &#x20;

[**See Unity Manual for guidance in managing UI element Layout using RectTransform**](https://docs.unity3d.com/2020.1/Documentation/Manual/UIBasicLayout.html)

![Click the Square with red-cross to open Anchor Presets, above is the default setting for UI-Text](https://1118975008-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0-KLgOacVpbicrqehO%2F-MFCU5DzgRZyPawXgCAk%2F-MFCX3oOefv6v-BKxTF4%2FScreen%20Shot%202020-08-20%20at%203.13.08%20PM.png?alt=media\&token=4e977b67-6190-4eaf-9f48-5df55239392a)

![Image above shows the position, anchors are set to the bottom of the canvas](https://1118975008-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0-KLgOacVpbicrqehO%2F-MFCU5DzgRZyPawXgCAk%2F-MFCXockeiuO1MphSwPM%2FScreen%20Shot%202020-08-20%20at%203.14.31%20PM.png?alt=media\&token=7ab7a6b4-7638-4e0a-9346-99a3ae681188)

![Switch to Game view and take a screen-shot.  Paste into a word document and submit for assignment 1.](https://1118975008-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-M0-KLgOacVpbicrqehO%2F-MFCadcse4chmxa95UxJ%2F-MFCah3I5Z2NLauj0ix6%2FScreen%20Shot%202020-08-20%20at%203.29.09%20PM.png?alt=media\&token=cb45c4da-6628-4bc2-adf5-00d8beb29208)
