We can also add 3D widgets directly within the environment, as shown:
In order achieve this, we must create an empty GameObject as a child of the Ground
GameObject, which has the UIPanel
component attached to it for widget rendering.
After this, we can create our widget, place it at the desired location, and make sure it lies in the default environment camera layer instead of the usual UI layer.
Let's try it now:
Ground
GameObject.LevelName
.panel
to search for components with this name.Background
.As you can see in the following screenshot of the Scene view, our 360 x 100 sprite is gigantic!
The large size of our sprite is simply due to the fact that the widget's scaling is handled by the UI Root
component and our Ground
does not have UI Root
.
Instead of increasing the number of UI roots in our scene, we can simply set the LevelName
container's scale to a very small value; our widgets will then be displayed at a manageable size. Their Size
values won't be pixel perfect, but that's not a problem here since we are simply displaying widgets in the 3D environment:
Ground
| LevelName
GameObject.Ok, you should now have a reasonably-sized Background
sprite in the Game view, with a rotation, as if it were painted on the ground:
Good! We can now add a border sprite and a label to display the level's name:
Ground
| LevelName
GameObject.Carhel Castle
.Ground
| LevelName
| Background
GameObject:Ground
| LevelName
| Label
in the Target field.Background
sprite pressing Ctrl + D.Border
.Ok, great! We now have the level's name displayed in the 3D world, and the background and borders will adjust to always wrap the label. We can now move on to the lighting effects!
3.15.22.160