Create UI-Text GameObject
To complete Assignment 1
Last updated
To complete Assignment 1
Last updated
To create a Text GameObject, see image below: select GameObject > UI > Text
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.
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
See Unity Manual 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.
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.
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.
See Unity Manual for guidance in managing UI element Layout using RectTransform