How to fade a scene in/out

Hey guys

I was wondering, what is the most efficient and easy way to make a scene changing transitions…?

I was looking at http://answers.unity3d.com/questions/8540/how-to-fade-inout-a-scene.html but couldn’t seem to get it to work.
So far I have figured out that I need a texture over the screen or something like that, but I’m having a bit of trouble… :confused:

Thanks

-Grady

Well, if you want both the scenes to be moving during the transition, it can be pretty difficult. Just out of interest, are you using Unity Pro? If so, there is an easy way of faking a snapshot transition.

Duck's answer in the question you linked to is spot on. I'm afraid I don't really see the point of this question since it's already answered.

I'm using the free version of unity unfortunately... And for Eric5h5, I copied the code into a OnGUI() funtion, but I just got errors in the console.... I don't know what I am doing wrong....

Look at the errors, they're surprisingly helpful. Obviously directly copy-pasting won't work, you have to actually understand the code as well! You need to define a member variable on your script to store the current fade level.

1 Answer

1

You could draw a Black GUI Texture that fills the screen , whose Alpha would slowly ascend from zero to 1 , then load the level. Then you should set it that whenever the new level is loaded , a black texture is also drawn , but now it's alpha descends from 1 to 0 , that should make for a nice transition and should cover up the loading time.

Which, coincidentally, is exactly the same answer as the one from the link posted with the question!

Alpha goes from 0 to 1 though.

so would it be easier to draw the texture from code, or make the gui texture as a game object and then try and change it...?

OK, I managed to get something to work how I wanted it to... Here is the code I used: var theTexture : Texture2D; function OnGUI(){ GUI.color.a = Mathf.Lerp(0.0, 1.0, (Time.time / 2)); GUI.DrawTexture(Rect(0,0,Screen.width, Screen.height), theTexture); } That is if you want it to fade out straight away, i have to try and find a better value instead of Time.time /2 ...

How about storing a var alphaFade = 0; and a var fading = false; then do something like if(fading) { alphaFade += Time.deltaTime } Then use alphaFade to fade your thing in. This way, if you set fading to true, it will automatically fade out over the next second. As an added bonus, you could wrap it up with your loadlevel function- if(alphaFade >= 1) { Application.LoadLevel(some level); }