Game Development Reference
In-Depth Information
Instance.fadeInTime = aFadeInTime;
Instance.fadeColor = aColor;
StopAllCoroutines();
StartCoroutine("Fade");
}
As you can see, when fading starts, we set the flag to denote fading has started, capture
the values for the manager used to control the fading motion, stop any existing coroutines
from running that might be from the existing scene or a previous fading action, and kick
off the Fade coroutine.
All that's left to complete our FadeInOutManager script is the public function that
scenes will be able to use to kick off the process. The code for this script is as follows:
private void StartFade(
float aFadeOutTime,
float aFadeInTime,
Color aColor)
{
fading = true;
Instance.fadeOutTime = aFadeOutTime;
Instance.fadeInTime = aFadeInTime;
Instance.fadeColor = aColor;
StopAllCoroutines();
StartCoroutine("Fade");
}
Then, we need the following public static (available anywhere) function that you can use
to start the level fading process:
public static void FadeToLevel(
string aLevelName,
float aFadeOutTime,
float aFadeInTime,
Color aColor)
{
if (Fading) return;
Instance.navigateToLevelName = aLevelName;
Search WWH ::




Custom Search