- Home /
Fade in doesnt work when loading level
Hi,
I'm trying to make a game as a project for school. Currently I have got a couple of levels, and switching levels isnt the problem. The problem is the fade in. Whenever I complete a level, the fade-out works fine, then the next level gets loaded, but without any kind of fade in. If I load the level sepperately, the fade in does work.
fading.levelDone = true; yield WaitForSeconds(5);
Application.LoadLevel("Temple_of_Osiris_inside");
fading.levelDone = false;
this is in the first level, fading.levelDone handles the fading in and out like this:
function OnGUI() {
GUI.color = Color.black;
if(levelDone == true) {
GUI.color.a = Mathf.Lerp(0.0, 1.0, Time.time/13); // fade out
}
if(levelDone == false) {
GUI.color.a = Mathf.Lerp(1.0, 0.0, Time.time/2); // fade in
}
GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), theTexture);
}
Any ideas?
Thanks in advance!
Ok, hold on, look at me in the eyes. ....$$anonymous$$mmmmmm.....hold on.....Try to think about your code real hard....think about it harder.....mmmm no I cannot read your $$anonymous$$d. Sorry you will have to post the code for us to read it and help you.
ok ok Im sorry
fading.levelDone = true; yield WaitForSeconds(5); Application.LoadLevel("Temple_of_Osiris_inside"); fading.levelDone = false;
this is in the first level, fading.levelDone handles the fading in and out like this:
function OnGUI() { GUI.color = Color.black; if(levelDone == true) { GUI.color.a = $$anonymous$$athf.Lerp(0.0, 1.0, Time.time/13); // fade out } if(levelDone == false) { GUI.color.a = $$anonymous$$athf.Lerp(1.0, 0.0, Time.time/2); // fade in } GUI.DrawTexture(Rect(0, 0, Screen.width, Screen.height), theTexture); }
the second level has the same script, and of course, levelDone is set to false, so the fade in works when i load that level by hand
You set levelDone after LoadLevel so it does not happen. The lvel gets loaded before the value is changed.
Easiest way is to set it back in the Start function. Then when new scene loads, Start is called and the levelDone is set back to false.
I have a new script created and in there I have added a Start Function, and within there I set the levelDone back to false, but still the fade wont show up
Your answer
![](https://koobas.hobune.stream/wayback/20220613083202im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Player Mesh fade from one color to another 1 Answer
fading between skyboxes 1 Answer
fade between scenes? 1 Answer
How to fade a gameobject containing child objects in it 0 Answers
iTween FadeTo 1 Answer