Game Development Reference
In-Depth Information
static function FadeAndLoadLevel (level, color : Color, fadeLength :
float)
{
var fadeTexture = new Texture2D (1, 1);
fadeTexture.SetPixel(0, 0, color);
fadeTexture.Apply();
var fade = new GameObject (“Fade”);
fade.AddComponent(LevelLoadFade);
fade.AddComponent(GUITexture);
fade.transform.position = Vector3 (0.5, 0.5, 1000);
fade.guiTexture.texture = fadeTexture;
DontDestroyOnLoad(fadeTexture);
fade.GetComponent(LevelLoadFade).DoFade(level, fadeLength, true);
}
function DoFade (level, fadeLength : float, destroyTexture : boolean)
{
DontDestroyOnLoad(gameObject);
guiTexture.color.a = 0;
var time = 0.0;
while (time < fadeLength)
{
time += Time.deltaTime;
guiTexture.color.a = Mathf.InverseLerp(0.0, fadeLength, time);
yield;
}
guiTexture.color.a = 1;
yield;
Application.LoadLevel(level);
time = 0.0;
while (time < fadeLength)
{
time += Time.deltaTime;
guiTexture.color.a = Mathf.InverseLerp(fadeLength, 0.0, time);
yield;
}
guiTexture.color.a = 0;
yield;
Destroy (gameObject);
if (destroyTexture)
Destroy (guiTexture.texture);
}
3. Save your Unity scene and project.
If you play the game now, the zombie can kill and damage you and the level will reload
when you die. While this is certainly interesting, the battle is clearly one-sided. To even
things out, you will give the player a gun to shoot the zombie with.
Search WWH ::




Custom Search