Created
March 6, 2019 19:59
-
-
Save xSystemIOx/dfc2923145afaf53cb0030193624e37c to your computer and use it in GitHub Desktop.
Unity C# Loading screen
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public GameObject loadingScreen; | |
| public Slider slider; | |
| public Text progressText; | |
| public void LoadScene(int sceneIndex){ | |
| loadingScreen.SetActive (true); | |
| StartCoroutine (LoadAsync (sceneIndex)); | |
| } | |
| IEnumerator LoadAsync(int sceneIndex){ | |
| AsyncOperation asyncOperation = SceneManager.LoadSceneAsync (sceneIndex); | |
| while (!asyncOperation.isDone) { | |
| float progress = Mathf.Clamp01 (asyncOperation.progress / .9f); | |
| // loadingScreen.SetActive (true); | |
| slider.value = progress; | |
| progressText.text = (progress * 100).ToString("F0") + "%"; | |
| yield return null; | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment