Game Development Reference
In-Depth Information
Note Line 37 of Listing 8-5 will terminate game execution using the Application.Quit function. You
could adapt this code as follows to support application quitting from the editor, too:
#if UNITY_EDITOR
UnityEditor.EditorApplication.isPlaying = false;
#else
Application.Quit();
#endif
More information on the high-level Application class can be found in the Unity documentation at
https://docs.unity3d.com/Documentation/ScriptReference/Application.html .
HUD: Ammo and Health Statuses
CMOD now has a complete and working main menu for the GUI, except for load and save game
functionality, which are covered in the next chapter. Here, we'll focus our attention on some basic
text displays for a head-up display using the font rendering features provided by the GUI class and
its associated structures. The text created will display the Player health and any remaining ammo for
the active weapon. To achieve this, two C# classes will be coded, namely a label class ( GUILabel ) for
displaying text, and a GUIUpdate class, which relies on the label classes to display text on the screen,
describing health and ammo. Let's start with the label class, as shown in Listing 8-6.
Note A head-up display (or HUD) refers to all on-screen graphical displays that appear while the game is
being played (such as health bar and score).
Often, game developers avoid dynamic font rendering, as used here, for performance reasons. Instead, they
typically use a font atlas texture —that is, a texture file containing each alphanumeric character in a font set.
Text is then shown on-screen in-game like a regular sprite or texture, with various letters in the text combined
like sprites to form complete text statements and sentences. There are many programs available to produce
font atlas textures. One includes BMFont ( www.angelcode.com/products/bmfont/ ) . Dynamic fonts are
used here, however, to demonstrate basic GUI functionality and how to quickly render text on-screen. One
exceptional case to using atlas font textures might be rendering text from Asian-based languages, in which
the full character set is often too large to store inside a texture that performs well across multiple platforms.
 
Search WWH ::




Custom Search