Game Development Reference
In-Depth Information
}
// C# user:
void OnGUI() {
GUI.DrawTexture (new Rect (10,10,46,32),
textHpTexture);
GUI.DrawTexture (new Rect (10,42,95,32),
textAiTexture);
GUI.BeginGroup (new Rect (110,15,156,21));
GUI.DrawTexture(new Rect (0,0,156,21),
frameTexture);
GUI.BeginGroup (new Rect (0,0,player.HpPercent *
156, 21));
GUI.DrawTexture (new Rect (0,0,156,21), hpTexture);
GUI.EndGroup ();
GUI.EndGroup ();
GUI.BeginGroup (new Rect (110,47,156,21));
GUI.DrawTexture(new Rect (0,0,156,21),
frameTexture);
GUI.BeginGroup (new Rect (0,0,ai.HpPercent * 156,
21));
GUI.DrawTexture (new Rect (0,0,156,21), aiTexture);
GUI.EndGroup ();
GUI.EndGroup ();
}
In the preceding function, we just use the
GUI.BeginGroup()
function to
draw the mask for the hit-point bar.
4. Now, we will go back to Unity and drag the
HitPoint
script to the UI game ob-
ject in the
Hierarchy
view. Then, we will go to its
Inspector
view and set the fol-
lowing:
Hit Point UI (Script)
robotAI_C# (AI)
or
ro-
botAI_JS (AI)
Drag the
robotAI_C#
or
robotAI_JS
game object inside the
Enemy
game object
to the
Hierarchy
view
AI