Unity Freezes After SceneManager.LoadSceneAsync

Hi people!

So I’m trying to make a loading screen, with a breathing “loading” text.
Here’s how I implemented it before:

using System.Collections;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class SceneLoader : MonoBehaviour

    private Text _loadText;
	// Use this for initialization
    private void Start ()
        _loadText = GameObject.Find("Text").GetComponent<Text>();

	// Update is called once per frame
    private void Update ()

    private IEnumerator LoadScene()
        var prevScene = PlayerPrefs.GetInt("prevScene");
        yield return new WaitForSeconds(3);
        print("Loading scene now! BOOM");
        var async = SceneManager.LoadSceneAsync(prevScene == 0 ? 1 : 0);
        while (!async.isDone)
            var lerp = Mathf.PingPong(Time.time, 1f);
            _loadText.color = Color.Lerp(Color.black, Color.white, lerp);
        yield return async;


The problem with this script is that Unity freezes to death after it starts the loading process.
Currently my workaround (not exactly) is just avoid it and use SceneManager.LoadScene instead.
The scene loads like in 4 seconds so it there’s got to be something wrong with the code. Can anyone help me out? Thanks in advance!!!

Thats because you don’t have a yield in your while loop :stuck_out_tongue:
also not sure that Mathf.pingpong will work that way you want it to (don’t know pingpong out of mind but Time.time is something I doubt).

Not yielding from within the loop is definitely a problem, but the real problem is that even with yielding it still freezes. It goes from 0 to 0.9 directly with a freeze of few solid seconds in between. In other words, it looks like Unity is choking even if the coroutine is responsive.