As we are gathering game data about the player's performance, we can display that information on screen to the player's advantage.
Unity offers a collection of functions and constructs to display game data on the screen and create the Graphic User Interface (GUI) of your game. OnGUI()
is an important method available in Unity and used to create and control GUI elements to be displayed on the screen. Inside the function, it is possible to put lines of code that create interface controls such as text fields, buttons, and sliders at runtime. We advise you to check out the following link:
http://docs.unity3d.com/Manual/gui-Basics.html
In this recipe, we will use the OnGUI()
function to display game data. We will create a script to access the number of lives and the items collected, and display them on the screen.
We need a couple of screenshots to be used as icons too, so get ready to follow our instructions.