Game Development Reference
In-Depth Information
Objective Complete - Mini Debriefing
We just created the UI game object and the script, which we use to control the hit-point UI.
We also used GUI.BeginGroup() to mask the decreasing damage from either the player or
enemy hitpoints.
Classified Intel
In this secion, we have used GUI.BeginGroup() to mask out the texture to show
how much hit points are left. The GUI.BeginGroup() funcion must be close to GUI.
EndGroup() .
In our code, we basically created the first group to contain the background texture, which
is the bar frame. Then, we drew another group on top of the first group, which contains the
bar texture as a clip mask. This second group's width will relate to the hit-point value left for
the player or enemy, as shown in the following code:
//Draw the background group
GUI.BeginGroup (Rect (110,15,156,21));
GUI.DrawTexture(Rect (0,0,156,21), frameTexture);
// Create a second Group which will be clipped
GUI.BeginGroup (Rect (0,0, player.GetHpPercent() * 156, 21));
GUI.DrawTexture (Rect (0,0,156,21), hpTexture);
//End both Groups
GUI.EndGroup ();
GUI.EndGroup ();
From the preceding code, we can translate to the following diagram:
 
Search WWH ::




Custom Search