Game Development Reference
In-Depth Information
Transitions
When you are transitioning between scenes/levels within Unity, it can appear a bit jarring
to the player when a scene just freezes and then another one pops up. Even when you
make the loading of the scene as fast as possible, there is still a flicker on the screen that is
not smooth or fluid (as designers like to say).
Thankfully, we can easily fix this by adding some code to manage the transition between
the towns and world in our game. We will do this by adding a Fading manager to our
game.
To start off, in the same way as we did with the Conversation manager in the previous
chapter, we will create a new class and apply our singleton framework to it. This is simply
because there should only ever be one agent in our game managing the fading of a scene
so it does not cause an issue if a player enters and then immediately exits a scene.
So, create a new FadeinOutManager C# script in the root of your project's Assets
folder and replace its contents with the following code to create a singleton manager that
can be used by any scene:
public class FadeInOutManager : Singleton<FadeInOutManager>{
// guarantee this will be always a singleton only -
// can't use the constructor!
protected FadeInOutManager() { }
}
With this in place, we can start building the manager. First, start off with some properties
as shown in the following code:
// The texture to display when fading
private Material fadeMaterial;
// Fading parameters
private float fadeOutTime, fadeInTime;
private Color fadeColor;
//Place holder for the level you will be navigating to
//(by name or index)
private string navigateToLevelName = "";
private int navigateToLevelIndex = 0;
Search WWH ::




Custom Search