Graphical User Interface (GUI) design in Unity

3D Game Design with Unity

🕑 This lesson will take about 20 minutes

A Graphical User Interface (GUI) provides a way for the game to provide information to the user or to read information from the user. This can be in the form of labels, buttons, text boxes, sliders, menus, and so on. The GUI can sit on top of the actual game. It is always a good idea to design your GUI before making the game – draw up a storyboard or wireframe with the types of GUI controls you want in the game and where you want to place them.

GUIs are created within the Unity Editor or through code and can be controlled using code. GUI elements are usually added to the ‘canvas’ which acts like a heads-up display (HUD).

In order to add a GUI to your scene, you can either add them from the Unity Editor, or add a special method to the script you have created for your GUI which is attached to an object in your scene eg. the camera. The special method that is used to create a GUI is called OnGUI(). This method takes no parameters and returns no data to whatever called it. The method will draw your GUI components on the screen and is called every single frame, just like the Update() method. Different GUI controls (eg. labels, buttons) will have code that goes inside the OnGUI() method.

Watch the videos below to learn how to add and control different GUI elements in Unity.

Is YouTube blocked at school? Watch these videos on Google Drive instead.