Scripting the UI
We previously created a UI layout with elements such as bars, text, and buttons, but so far, they are static. We need to make them adapt to the game's actual state. In this chapter, we are going to discuss the following UI scripting concepts:
- Showing information in the UI
- Programming the Pause menu
We will start by seeing how to display information on our UI using scripts that modify the text and images that are displayed with Canvas elements. After that, we will create the Pause functionality, which will be used throughout the UI.
Showing information in the UI
As discussed earlier, we will use the UI to display information to the user to allow them to make informed decisions, so let's start by seeing how we can make the player's health bar react to the amount of life they have left in the Life
script we created earlier:
- Add a new script called Life Bar to the HealthBar Canvas child object, which is the UI
Image
component...