Skip to content

Instantly share code, notes, and snippets.

@niiicolai
Created October 6, 2021 14:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niiicolai/3aa3e32f066a61d28d9baa4eaa51b49c to your computer and use it in GitHub Desktop.
Save niiicolai/3aa3e32f066a61d28d9baa4eaa51b49c to your computer and use it in GitHub Desktop.
A simple script that loads a new scene async. and display the progress while loading.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class StartMenu : MonoBehaviour
{
[SerializeField]
private string sceneName = "SampleScene";
[SerializeField]
private GameObject loadPanel = null;
[SerializeField]
private Text loadText = null;
private void Start()
{
loadPanel.SetActive(false);
}
public void Play()
{
StartCoroutine(LoadSceneAsync());
}
private IEnumerator LoadSceneAsync()
{
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneName);
loadPanel.SetActive(true);
while (!asyncLoad.isDone)
{
loadText.text = asyncLoad.progress + "%";
yield return null;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment