需要三个场景
A(第一个场景)
B(进度条场景)
C(第二个场景)
两个代码
(1)放置在A场景中,点击跳转至B场景
public void Go()
{
SceneManager.LoadScene("B");
}
(2)放置在B场景中的载入文本的身上
public class SceneTrans : MonoBehaviour
{
//公开一个滑动条
public Slider LoadingSlider;
//公开载入文本(代码放置载入文本身上)
public Text LoadText;
//公开字符串用于填写第三个场景的名称
public string SceneName;
private float TargetVaule;
private AsyncOperation async = null;
void Start()
{
LoadText = GetComponent
LoadingSlider = FindObjectOfType
StartCoroutine(AsyncLoading());
}
IEnumerator AsyncLoading()
{
//异步加载场景
async = SceneManager.LoadSceneAsync(SceneName);
//阻止当加载完成自动切换
async.allowSceneActivation = false;
while (!async.isDone)
{
if (async.progress < 0.9f)
{
TargetVaule = async.progress;
}
else
{
TargetVaule = 1.0f;
}
LoadingSlider.value = TargetVaule;
LoadText.text = (int)(LoadingSlider.value * 100) + "%";
if (TargetVaule >= 0.9)
{
async.allowSceneActivation = true;
}
yield return null;
}
}
}
在Unity中设置即可自动跳转至C场景



