Game Development Reference
In-Depth Information
public Texture2D hpTexture;
public Texture2D aiTexture;
public Texture2D textHpTexture;
public Texture2D textAiTexture;
void Update() {
if ((player.HpPercent <= 0.0f) || (ai.HpPercent
<= 0.0f)) {
CharacterClass.IS_GAMEOVER = true;
StopAllCoroutines();
}
}
}
3. Next, we will add the OnGUI() function to create the hit-point UI as follows:
// Unity JavaScript user:
function 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 ();
Search WWH ::




Custom Search