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 ()
{
StartCoroutine("LoadScene");
}
private IEnumerator LoadScene()
{
var prevScene = PlayerPrefs.GetInt("prevScene");
print(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!!!