Game Toolkit for Unity
Setting up the game’s UI.
In this tutorial we’ll set up the HUDs to display the player’s health, score and bombs, as well as the flying text UI prefab.
If you remember, we’ve already set the Makinom project’s UI system to use the Unity UI module, i.e. we’ll do most of the setup in the scene, using components and the Unity UI. You can learn more about UI systems in general in this documentation, or about the Unity UI module in this documentation.
First, let’s set up the flying text prefab – we’ll use it in the EnemyDeath schematic to actually show the points.
The easiest way to set up a UI box is using the context menu in the scene hierarchy: Makinom > UI > Flying Text (TextMesh Pro)
This already gives us all we need for a basic flying text, but we can style it to our liking, e.g. change the font, font size or alignment. We also need to set up the additional content (points content ID).
I’ll change the font size – select the Text child object of the created Flying Text game object and change the TextMesh Pro – Text (UI) component’s settings.
We’ll add an additional content to the flying text (have the Flying Text game object selected) using the context menu: Makinom > UI > Flying Text – Additional Content (TextMesh Pro)
The newly created Additional Content game object should now be selected.
The text should be displayed below the main text.
I’ll change the font size – select the Text child object of the created Additional Content game object and change the TextMesh Pro – Text (UI) component’s settings.
We need to set the content ID for the additional content. The content itself has already been added to the UI Flying Text component as additional content.
Select the Flying Text game object and change the following settings in the UI Flying Text component in Content > Additional Content 0.
That’s it for the flying text setup – now create a prefab out of it by dragging the Flying Text game object from the scene hierarchy to the project view, e.g. into a new folder in Assets/Tutorial Resources/Prefabs/UI/.
Next, we’ll set up the bomb HUD – it’ll simply display an image in the lower left corner of the screen
Use the context menu in the scene hierarchy to add a simple HUD: Makinom > UI > HUD > HUD
Add an Image component to the game object using the component menu.
Click on Set Native Size to use the sprite’s actual size for the UI game object’s size.
The image is now pretty big – scale it down a bit using the Rect Tool, dragging one corner while holding shift until it’s about 160×130.
Now move it to the lower left corner of the canvas.
That’s it for the bomb HUD – create a prefab out of it and rename it, e.g. to Bomb HUD.
Next, we’ll set up the HUD to display the player’s health. It’ll be displayed above the player, so we don’t really need to do any changes to the position (just keep it at Pos X/Y=0).
We’ll display the health as a value bar, use the context menu to add it to the HUD game object: Makinom > UI > HUD > Bar > Value Bar Content
Move and size the bar to your liking, I’m using these settings to have it fit within the background image we just added:
The HUD Value Bar Content component is responsible for handling the numbers/values the bar represents. We’ll use it to show the player’s HUD – the player is the User of the HUD, i.e. we can access the player’s object variables via that object.
The Value handles the current value of the bar.
The Minimum Value defines the minimum value (i.e. an empty bar) represents.
The Maximum Value defines the maximum value (i.e. a full bar) represents.
Delete the Empty Sprite child object, we don’t display an empty bar/background.
Select the Value Sprite child object and change the Image component’s settings to use a color similar to the heart image.
That’s it for the health HUD – create a prefab out of it and rename it, e.g. to Health HUD.
Now, we’ll set up the HUD to display the player’s score. We’ll show it at the top of the screen.
Change the newly created HUD’s Rect Transform:
Now move it to the top of the canvas, it should now be placed at the top across the whole width of the screen.
Add a HUD Text Content to the HUD using the scene hierarchy context menu: Makinom > UI > HUD > Content > Text Content (TextMesh Pro)
Adjust the new game object’s bounds to match the parent HUD’s bounds (e.g. using stretch stretch anchor preset).
This component is responsible for setting the TextMesh Pro component’s text in the HUD, we’ll use a Makinom text code to show the value of our lives int variable.
You can display int variables using the text code <var.int=key>, replacing key with the variable key you want to show.
We’ll use a larger font size and place it in the center – select the Text child object of the created Text Content game object and change the TextMesh Pro – Text (UI) component’s settings.
That’s it for the score HUD – now create a prefab out of it by dragging the HUD game object from the scene hierarchy and rename it, e.g. to Score HUD.
With that we’re done with the setup of our UI prefabs, but we need to clean up the Canvas and Event System that where created by Unity for our UI setup in the scene. In the scene hierarchy, select the Canvas and EventSystem game objects and delete them (e.g. via the Delete key).
All that’s left to do is use the UI prefabs we just set up in Makinom.
Open the Makinom editor, navigate to UI > HUDs and select the Default HUD that’s already been added in the initial project setup. Change the following settings.
Add a new HUD and change the following settings.
We only display the HUD when the player has bombs, i.e. the global variable bombs is greater than 0.
Click on Add Variable Condition and change the following settings.
That’s it for the HUDs – click on Save Settings to save the changes.
Finally, we need to use the flying text prefab – navigate to Schematics and open the EnemyDeath schematic.
Select the Show Flying Text node and change the following settings.
And that’s it – click on Save Schematic to save the changes.
Click on Play to start the game. You’ll now see the player’s health HUD above the player and the score in the upper center of the screen. After collecting a bomb, you’ll see the bomb HUD in the lower left corner of the screen.
The next tutorial will handle the background animations.
© 2015 Gaming is Love e.U.
Disclosure: This site may contain affiliate links, which means I may receive a commission if you click a link and purchase something that I have recommended. While clicking these links won’t cost you any money, they will help me fund my development projects while recommending great assets!