Search
 
SCRIPT & CODE EXAMPLE
 

CSHARP

loading screen unity

using System.Collections;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
using TMPro;

public class LoadingScreen : MonoBehaviour
{
	[HideInInspector]
	private TextMeshProUGUI loadingText;
	[HideInInspector]
	private Slider loadingSlider;

	public void LoadScene(int sceneNumber)
	{
		StartCoroutine(LoadSceneAsync(sceneNumber));
	}

	IEnumerator LoadSceneAsync(int sceneIndex)
	{
		AsyncOperation operation = SceneManager.LoadSceneAsync(sceneIndex);

		while (!operation.isDone)
		{
			Debug.Log("Operation progress");

			float progress = Mathf.Clamp01(operation.progress / 0.9f);

			loadingText.text = Mathf.RoundToInt(progress * 100) + "%";
			loadingSlider.value = progress;

			yield return new WaitForEndOfFrame();
		}
	}
}
Comment

loading screen unity


IEnumerator load(){
    yield return null;

    //Begin to load the Scene you specify
    AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneIndex);
    //Don't let the Scene activate until you allow it to
    asyncOperation.allowSceneActivation = false;
    Debug.Log("Pro :" + asyncOperation.progress);
    //When the load is still in progress, output the Text and progress bar
    while (!asyncOperation.isDone)
    {
        //Output the current progress
        Debug.Log("Loading progress: " + (asyncOperation.progress * 100) + "%");

        // Check if the load has finished
        if (asyncOperation.progress >= 0.9f)
        {
            //Change the Text to show the Scene is ready
            asyncOperation.allowSceneActivation = true;
        }

        yield return null;
    }
}

Comment

PREVIOUS NEXT
Code Example
Csharp :: unity keycode for f 
Csharp :: unity assembly 
Csharp :: how to access individual characters in a string in c# 
Csharp :: mvc 5 dropdownlist 
Csharp :: untiy instanciate prefab 
Csharp :: linux command line switch statement 
Csharp :: c# check if 2d array position exists 
Csharp :: instantiate unity 
Csharp :: Get key by his value on Dict C# 
Csharp :: how get query from url in laravel 
Csharp :: how to clone something unity 
Csharp :: c# make request to rest api 
Csharp :: forech unity 
Csharp :: unity c# debug.log 
Csharp :: unity object change sprite 
Csharp :: c# datagridview cell click event 
Csharp :: defaultrequestheaders.authorization basic auth 
Csharp :: dynamic arrays in c# 
Csharp :: The server requested authentication method unknown to the client 
Csharp :: No Entity Framework provider found for the ADO.NET provider with invariant name 
Csharp :: ienumerable count 
Csharp :: c# byte 
Csharp :: asp.net core get root url in view 
Csharp :: initialize list in c# 
Csharp :: how to get text from textbox in windows form c# 
Csharp :: database update dotnet 
Csharp :: c# write to output window 
Csharp :: c# getting user input 
Csharp :: webclient timeout 
Csharp :: calling stored procedure in c# entity framework 
ADD CONTENT
Topic
Content
Source link
Name
1+7 =