Skip to content

Instantly share code, notes, and snippets.

@xSystemIOx
Created March 6, 2019 19:59
Show Gist options
  • Select an option

  • Save xSystemIOx/dfc2923145afaf53cb0030193624e37c to your computer and use it in GitHub Desktop.

Select an option

Save xSystemIOx/dfc2923145afaf53cb0030193624e37c to your computer and use it in GitHub Desktop.
Unity C# Loading screen
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