Game Development Reference
In-Depth Information
2. Next, create a new script by going to Assets | Create | Javascript , name it
HitPointUI , double-click on it to open MonoDevelop , and replace it with the
following code:
public var ai : AIController;
public var player : New3PSController;
public var frameTexture : Texture2D;
public var hpTexture : Texture2D;
public var aiTexture : Texture2D;
public var textHpTexture : Texture2D;
public var textAiTexture : Texture2D;
Here, we just set up all the parameters needed for our HitPointUI .
3. Then, add the Update() funcion to check for the game over state:
public function Update() : void {
//Checking if the player or AI Hit-point equal 0 or below 0
if ((player.GetHpPercent() <= 0.0) || (ai.GetHpPercent() <=
0.0)) {
StaticVars.b_isGameOver = true;
}
}
4. We will add the OnGUI() funcion to create the hit-point UI:
public function OnGUI() : void {
//Draw Text
GUI.DrawTexture (Rect (10,10,46,32), textHpTexture);
GUI.DrawTexture (Rect (10,42,95,32), textAiTexture);
//Character Hp
// Create one Group to contain both images
// Adjust the first 2 coordinates to place it somewhere else on-
screen
GUI.BeginGroup (Rect (110,15,156,21));
// Draw the background image
GUI.DrawTexture(Rect (0,0,156,21), frameTexture);
// Create a second Group which will be clipped
// We want to clip the image and not scale it, which is why we
need the second Group
GUI.BeginGroup (Rect (0,0,player.GetHpPercent() * 156, 21));
// Draw the foreground image
GUI.DrawTexture (Rect (0,0,156,21), hpTexture);
// End both Groups
GUI.EndGroup ();
GUI.EndGroup ();
 
Search WWH ::




Custom Search