1. newly build 3 Scenes
2. stay Canavs Plus plus MyLevelManager script , Build one Button, Register click events .
3. The progress bar needed to make the second scene ( Remember to put Handle Slide
Area Delete ).Text The content in the table is the loading progress number . same Canavs Hang up MyLevelManager script , Remember to give Inspector script slider and text assignment ( Drag in ).
4. The third scenario , Casually created and copied some Cube, Look at your mood , You can also find some cool large-scale scene resources .
be careful :MyLevelManager Script needs to be hung on 01-Begin Scene and 02-Loding scene of Canavs upper .
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class MyLevelManager : MonoBehaviour {
static string nextLevel;// Static data , Do not destroy
public Slider slider;
public Text text;
public float tempProgress;
AsyncOperation async;
public void LoadLodingLevel(string nextLevelName)
{
SceneManager.LoadScene("02-Loding");
nextLevel = nextLevelName;
}
private void Start()
{
tempProgress = 0;
if (SceneManager.GetActiveScene().name ==
"02-Loding")// If the currently active scene is Loding scene
{
async = SceneManager.LoadSceneAsync(nextLevel);// The next scene is loaded asynchronously
async.allowSceneActivation = false;// Do not jump to the next scene when the scene is loaded
}
}
private void Update()
{
if(slider && text)
{
tempProgress = Mathf.Lerp(tempProgress, async.progress/9*10,
Time.deltaTime * 2);// Smooth load progress bar ;async.progress yes 0~0.999 One of float value
text.text = ((int)(tempProgress/9*10 * 100)).ToString() + "%";
slider.value = async.progress/9*10;
if (tempProgress/9*10 >= 0.9)
{
tempProgress = 1;
text.text = 100+ "%";
slider.value = 1;
async.allowSceneActivation = true;// Set the value to true to jump to the next scene
}
}
}
}
Technology