Game Development Reference
In-Depth Information
//State to control if a level is fading or not,
//including public property if access through code
private bool fading = false;
public static bool Fading
{
get { return Instance.fading; }
}
The properties are documented and used to control how long the fade should last when
leaving the current scene into the next; there is an additional Material property so that
you can use different textures to display on the screen when fading (maybe your game
logo). Finally, there are some tracking properties if you are using the class to navigate
scenes by index or scene name.
With the properties in place, we now need the following initialization code:
void Awake () {
//Setup a default blank texture for fading if none is
supplied
fadeMaterial = new Material("Shader \"Plane/No zTest\"
{" +
"SubShader { Pass { " +
" Blend SrcAlpha OneMinusSrcAlpha " +
" ZWrite Off Cull Off Fog { Mode Off } " +
" BindChannels {" +
" Bind \"color\", color }" +
"} } }");
}
In the previous code, we are simply setting up a default fading material in case you don't
pass one as a parameter.
Note
At the moment, this material would be overwritten the first time the manager is used to
fade with a new material (defaults to the last material used). If you want to apply a materi-
al in the editor or use a prefab material, then remove or update this section of code.
Search WWH ::




Custom Search