- Home /
Fade out issue
Well I'll try to explain this issue as best as I can although English is not my native language (sorry about that).
Basically I'm trying to switch between two scene with Application.LoadLevel("BLABLA") and in order to smooth the transition I coded a simple Fade-In Fade-Out using a GUI.
The problem I'm having is on the fade-out to the next scene, apparently after it's done fading out and the scene is "destroyed" the first thing which disappears is the black textured GUI which makes the whole effect. And the result is for a couple milliseconds you get to see the last scene with out the gui black out which causes a "flickering" fade-out.
In a simple way : Scene One -> Starts Fade-out -> Ends Fade-out -> *For a couple of milliseconds you see Scene One-> Moves to the next scene -> Fade-in normally -> Scene Two
here are parts of my code
void OnGUI()
{
if(isFadingIn)
{
alphaFadeValue -= Mathf.Clamp01(Time.deltaTime / fadeTime);
GUI.color = new Color(0, 0, 0, alphaFadeValue);
GUI.DrawTexture(rect, blackTexture);
if(alphaFadeValue <= 0)
isFadingIn = false;
}
if(isFadingOut)
{
alphaFadeValue += Mathf.Clamp01(Time.deltaTime / fadeTime);
GUI.color = new Color(0, 0, 0, alphaFadeValue);
GUI.DrawTexture(rect, blackTexture);
if(alphaFadeValue >= 1)
isFadingOut = false;
}
}
public bool isDone()
{
// Debug.Log(isFadingIn.ToString() + " " + isFadingOut.ToString());
if(!isFadingIn && !isFadingOut)
return true;
return false;
}
Switch scene part:
void Start ()
{
fe = (FadeEffect)GameObject.Find ("Fade").GetComponent(typeof(FadeEffect));
fe.fadeIn();
}
// Update is called once per frame
void Update ()
{
if(fe.isDone())
{
if(Input.GetButtonDown("Fire1") && !startMove)
{
startMove = true;
fe.fadeOut();
}
if(fe.isDone() && startMove)
Application.LoadLevel ("BlaBla");
}
}
I think the solution is somehow make the fade object (The script with the gui stuff) destroyed last on Application.LoadLevel("Bla") but the problem is I have no idea how to implement this kind of thing.
A lot of thanks for whoever could sort this out! Sorry for the long question!
You can just simply do DontDestroyOnLoad(); and pack this script into some empty go.
Your answer
Follow this Question
Related Questions
Fade logo before main menu 2 Answers
FadeIn/FadeOut GUI Menu and Text 1 Answer
Fade in/out continously 1 Answer
GUI fade in Fade out 2 Answers
Fade GUITexture 1 Answer