UGUI Text Update: Overview
Most games today actually use UGUI for updating in-game text. UGUI (Unity Game User Interface) is, in most cases, very useful, as it provides valuable information to the player. By publicly displaying UGUI, the game player learns to understand the game much better. Compared to classic games without graphics and UI. I myself have several games that use UGUI to provide information to the player. Such as game statistics for interactions between objects. Without UGUI, players often find the game hard to play because it does not provide useful information. Usually, beginner players also find it hard to understand the game carefully, since it requires them to read in-game information. Some games do not provide a UI because they focus on exploring and finding things instead. The game also provides a manual for the player with hints to discover certain things.
UGUI Text Update: Recap
Previously, I explained how to add UGUI to a game by installing a package from the official Unity Package Manager—one of the essentials for Unity development. Even though Unity now offers UI Toolkit as the latest and recommended UI system, in this tutorial I still use UGUI (Unity Game User Interface) because it’s easier for beginners and it’s what I first learned with. I didn’t understand UGUI’s full potential at the time, but I’ve kept up with new ways to use it, and this post shares some of that knowledge. Note: This is just a small tutorial section on using UGUI to show information to the player in-game.
UGUI Text Update: Assigning The Text Variable
In this tutorial post, I need to assign the text variable in the code that I previously wrote in Visual Studio. I explain how the code actually works with the singleton that helps call the function in the UI Manager. To assign the variable, the user just needs to drag the Text object in the Hierarchy panel to the Inspector of the UI Manager. Alternatively, the user can select the variable icon on the GameObject Inspector to find the UGUI Text GameObject in the Hierarchy panel. After you assign the variable in the Inspector, you prevent errors during gameplay when the GameObject is actually null. Assigning the UGUI reference usually lets the system recognise the component and GameObject so it can access it in the code.

Calling the UI Manager Singleton
The UI Manager previously hosted the scoreText variable, which updates the score value when the player picks up a coin. The UI Manager then adds this coin to the score when the player also makes a collision trigger. The score system in the game helps the player gain certain achievements, especially when there are items and enemies. The valuable score shows what the player gets in return for playing and also allows them to compare their score with other people. Before calling the function, check your function; if it is missing, the code in the square game object scripts will not show it. Making the function public instead of private also helps the player avoid visibility issues in the game. Now the UI Manager scripts can call two methods. I believe that the score system script is the best.
On The Score System Script
I decided that the SquareScoreSystem script is the best choice for updating text information in the UI Manager. The other one, which is the CoinTrigger, can actually be used, but I already call the score from the CoinTrigger. The SquareScoreSystem script is the best choice because after it adds score, the UGUI can be updated. So, in the AddScore function, just add and call the singleton UI Manager script with its functions. The previous function or method name in the UI Manager script is UpdateScore, with the parameter score. Using score from the SquareScoreSystem script, put that into the parameter while calling the UI Manager function. After you call the singleton from the UI Manager script, save and compile the script to return to the Unity game engine.

Game Play Footage After Adding UGUI
Now, in the Unity game engine, after compiling, press the Play button. When you move the player square game object around the ground game object, you can make it collide with other objects such as coins. The collision with the coin game object will add to the score in the game. This also increases the score when there are multiple coin game objects available on the screen. To test this, you can duplicate the coin game object and position the copies in different places. Make sure the positions of the coin game objects allow them to collide with the square player so that they can be collected. As you can see in the picture below, the coin game object is picked up by the square player game object and the score is updated.

Conclusion From Adding UGUI Text and Code
In conclusion, you have now managed to add UGUI and update the text information in the game project. This started with adding the score system before proceeding to add UGUI and implement the coding system in the game. Before that, there was also a tutorial on how to add a game object, make a square game object move, handle collisions, use the Sprite Renderer, and more. The next tutorial is about adding background music and sound effects to the game. The sound effect will be used when the player collides with the coin, which will then produce a sound. The background music is what plays in the background, and I will use halal and permissible music for that. Let me know what you think in the comment section.
I drafted this article from my own perspective and used AI to polish the language.
Concept art (created with generative AI, touched up manually).





Leave a Reply