Game Development Reference
In-Depth Information
9. Once your texture is changed, adjust the settings so they match the ones shown in
Figure 10.15. The texture appears in the lower-left portion of the screen.
Figure 10.15
Adjusting the set-
tings of the GUI
texture so it is in the
lower-left part of
the screen
10. Select the Player object again and put your new HealthGUI object into the Health GUI
variable slot of the FPSPlayer object.
11. Save your scene and project.
Now that you have a way for the player to take damage and die, you need a way for the
game to reload itself so players can continue playing your game.
Making the Level Reload
he FPSPlayer.js script cannot work correctly until you give it a way to reload the level
when the player dies. In this section, you will create this code. The script in the next exer-
cise resets the game level after it has been called by another script—in this case when the
player has died—to a stored state. Much of this code is focused on controlling the time
and visual elements of how the scene fades back to its original state. This code specifies a
white colored screen upon transition, but the FPSPlayer.js script overrides that color by
making the screen fade color red when the player dies.
1. If it is not already open, open your Unity file.
2. Use the Project view's Create menu to create a new JavaScript file called LevelLoadFade
.js in your Scripts folder. Type the following code into the new script file:
static function FadeAndLoadLevel (level, fadeTexture : Texture2D, r
fadeLength : float)
{
if (fadeTexture == null)
FadeAndLoadLevel(level, Color.white, fadeLength);
var fade = new GameObject (“Fade”);
fade.AddComponent(LevelLoadFade);
fade.AddComponent(GUITexture);
fade.transform.position = Vector3 (0.5, 0.5, 1000);
fade.guiTexture.texture = fadeTexture;
fade.GetComponent(LevelLoadFade).DoFade(level, fadeLength, false);
}
 
Search WWH ::




Custom Search