Answers for "loading bar scene unity"

C#
0

loading bar scene unity

//LOADING BAR CORE
	private IEnumerator LoadAsync(string sceneName)
	{
		AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName);
		
      	//repeat until finished loading
		while(!operation.isDone)
		{
          	//get the progress value
			float progress = Mathf.Clamp01(operation.progress / 0.9f);
        	//update loading slider
			loadingSlider.value = progress;
        	//update loading text
			loadingText.text = ((int)(progress * 100)).ToString() + "%";
			//IEnumerator requires to yield something
          	yield return null;
		}
	}
Posted by: Guest on September-28-2021
0

loading bar scene unity

//LOADING BAR USING TEXT MESH PRO TEXT
using System.Collections;
using TMPro;

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.SceneManagement;


public class LoadingScreen : MonoBehaviour
{
    
    [SerializeField]
	private Slider loadingSlider;
	[SerializeField]
	private TextMeshProUGUI loadingText;
	[SerializeField]
	private UnityEvent OnLoadScene;
    
    public void OpenScene(string sceneName)
	{
		OnLoadScene.Invoke();
		StartCoroutine(LoadAsync(sceneName));
	}
	
	private IEnumerator LoadAsync(string sceneName)
	{
		AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName);
		
		while(!operation.isDone)
		{
			float progress = Mathf.Clamp01(operation.progress / 0.9f);
			loadingSlider.value = progress;
			loadingText.text = ((int)(progress * 100)).ToString() + "%";
			yield return null;
		}
	}
}
Posted by: Guest on September-28-2021
0

loading bar scene unity

//LOADING BAR USING NORMAL UNITY TEXT
using System.Collections;

using UnityEngine;
using UnityEngine.UI;
using UnityEngine.Events;
using UnityEngine.SceneManagement;


public class LoadingScreen : MonoBehaviour
{
    
    [SerializeField]
	private Slider loadingSlider;
	[SerializeField]
	private Text loadingText;
	[SerializeField]
	private UnityEvent OnLoadScene;
    
    public void OpenScene(string sceneName)
	{
		OnLoadScene.Invoke();
		StartCoroutine(LoadAsync(sceneName));
	}
	
	private IEnumerator LoadAsync(string sceneName)
	{
		AsyncOperation operation = SceneManager.LoadSceneAsync(sceneName);
		
		while(!operation.isDone)
		{
			float progress = Mathf.Clamp01(operation.progress / 0.9f);
			loadingSlider.value = progress;
			loadingText.text = ((int)(progress * 100)).ToString() + "%";
			yield return null;
		}
	}
}
Posted by: Guest on September-28-2021

C# Answers by Framework

Browse Popular Code Answers by Language