Waiting for fading to end before switching scenes
Hi! I have been dealing with fading between scenes system for my game, and had some major issues. Some of them I managed to deal with myself, but one of them is still there. A new scene loads although fading hasn't finised yet, so this makes a transition between them look kind of sharp instead of smooth. In addition I don't know how to make it so a new scene would fade out after the previous scene faded in. Here is the code:
public class LevelManager : MonoBehaviour
{
IEnumerator FadeToNextLevel()
{
float fadetime = GameObject.Find("FadeObj").GetComponent<Fading>().BeginFade(1);
yield return new WaitForSeconds(fadetime);
Application.LoadLevel(Application.loadedLevel + 1);
}
public void LoadLevel()
{
StartCoroutine("FadeToNextLevel");
}
public void QuitRequest()
{
Debug.Log("Quit requested");
Application.Quit();
}
}
The script for actual fading is working okay, so I guess the problem should be here. I searched for the solution and I think I should do something with WaitForSeconds method, but I don't know where to put it. The tutorial I have been using: link. Anyone knows how to fix this? Thank you!
Your answer
Follow this Question
Related Questions
c# shooting problem (probably pretty simple) 2 Answers
How to interrupt wait coroutine in a loop? 0 Answers
Help with changing bool over time to play animation 1 Answer
IENumerator does not work 0 Answers