So I'm trying to make a loading screen, with a breathing "loading" text. Here's how I implemented it before:
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);
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!!!
Answer by MaskedMouse
2 days ago
Thats because you don't have a yield in your while loop :P 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).
Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.
The best place to ask and answer questions about development with Unity.
To help users navigate the site we have posted a site navigation guide.
If you are a new user to Unity Answers, check out our FAQ for more information.
Make sure to check out our Knowledge Base for commonly asked Unity questions.
If you are a moderator, see our Moderator Guidelines page.
We are making improvements to UA, see the list of changes.
Answers and Comments
315 People are following this question.
How to stop objects you picked up from reappearing when you go to another level and return
How do I access a variable from a different scene using C#?
Multiple Cars not working
Distribute terrain in zones
Open door = load scene c# issues