Skip to content

Instantly share code, notes, and snippets.

@niiicolai
Created Oct 6, 2021
Embed
What would you like to do?
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