- Home /
Question by
oscar70701 · Jun 08, 2018 at 01:07 PM ·
c#unityeditorrestart
how to restart scane on click (unity2017.4.2f2)
using System.Collections; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI;
public class LevelLoader : MonoBehaviour {
public GameObject loadingScreen;
public Slider slider;
public void LoadLevel (int sceneIndex)
{
StartCoroutine (LoadAsynchrosly (sceneIndex));
}
IEnumerator LoadAsynchrosly (int sceneIndex)
{
AsyncOperation operation = SceneManager.LoadSceneAsync (sceneIndex);
loadingScreen.SetActive(true);
while (!operation.isDone)
{
float progress = Mathf.Clamp01 (operation.progress / .9f);
Debug.Log (progress);
slider.value = progress;
yield return null;
}
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612164357im_/https://answers.unity.com/themes/thub/images/avi.jpg)