Chapter 12. The User Interface

This is a great time to introduce some UI (User Interface) into our game. We will construct and implement a simple, dynamic user interface using Unity's built-in UI system.

In this chapter, we will cover the following topics:

  • Introducting the Unity UI
  • Creating UI Views
  • Connecting buttons to actions
  • Switching UI views

So far, our sole focus was on learning how to code. I would like to make a little exception in this chapter and talk about coding the UI functionality as well as creating a good-looking UI. You probably already know what a user interface is, right? If not, we will cover it very briefly.

A UI is a bridge between a human and a computer program. All user interactions with your game will be happening in the user interface. In simple words, all buttons on the screen, labels, as well as mouse- and keyboard-driven events are part of the UI.

The main part of the UI is the Graphical User Interface (GUI). The GUI is simply whatever is visible on the screen. All graphical elements that the user can interact with to control the game constitute the GUI:

The User Interface

This is an example of a very simple GUI panel that allows the user to choose what to do. It contains four simple buttons. They are easy for the user to interact with. We will also create a simple and easy-to-operate UI for our game.

Introducting the Unity UI

There are some great UI solutions available on the Unity Asset store. One of the best and my favorite is NGUI. I have used it for many years without any major issues. In fact, NGUI was so good that Unity Technologies decided to hire its developer to create a new UI system for Unity 4.6. Currently, the Unity UI system is the best choice. It is also built-in and does not require any Asset store purchases. Let's learn how to use it.

Good to mention here is that Unity UI is a tiny part of the Unity source code that is actually open source. What does this mean? It means you can download and edit Unity UI code to fit your purpose. I understand that your coding skills are not up to that level yet, but I thought it is worth mentioning for future reference.

If you ever decide to play around with the UI source code, here is the link: https://bitbucket.org/Unity-Technologies/ui.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset