Game Development Reference
In-Depth Information
Note
The OnGUI function acts in a similar way to an Update function, but OnGUI gets called
more than once for rendering and handling the GUI events, meaning that the OnGUI im-
plementation might be called several times per frame (one call per event), which means it
is recalculated at least twice per frame, which can make it slow than another GUIEle-
ment ( GUITexture or GUIText ). More importantly, each GUI object will also create
one or more draw calls, which means that this can cause a performance hit easily. So, it's
not recommended to use OnGUI for the in-game UI (especially in game development), in-
stead, we can use GUIElement .
Draw calls is how many materials from each object are being drawn to the screen. Around
200 to 300 draw calls is considered acceptable on a mobile platform.
Also, there are many remarkable UI tools in the assets store that are easier to implement
and they have a great performance for mobile development, such as the new GUI system
(uGUI) on Unity 4.6, NGUI (recommended), and EZGUI.
On the other hand, the GUI class can also be used with the editor class to create a cus-
tom inspector or window in Unity, which is very helpful. (We will learn about this in a
later project.)
In this project, we will apply the custom GUI graphics to Unity by using GUISkin . We
can have multiple styles for our GUI graphics in Unity. Let's say that we have multiple
types of fonts that we want to use in our menu; Unity has a way to do this. We can create a
GUISkin element and apply our custom skin to the area that we want to show the font in.
That is the great thing about Unity.
First, we will create the Item , ItemsContainer , and SkillsContainer classes to
contain our items and equipments. Then, we will create a menu scripting class that will
bring up a new menu window in the game scene when the player presses the M key. Next,
we will generate a script to create three tab buttons, which will take the player to each
window, STATUS , INVENTORY , and EQUIPMENT .
In the STATUS tab, we will create a script that will show the image of our character, hit
points, magic points, skills, and all attributes of this character. Next, we will create the
INVENTORY tab, which will contain all the items that the player can scroll up and down
to choose an item. Finally, we will create the EQUIPMENT tab that the player can use to
manage and change the equipments and skills of the character by clicking on it.
Search WWH ::




Custom Search