第一步:创建三个场景,分别为 A B C
第二步:shift+ctrl+b 分别把三个场景加载进去
第三步:开始干活
①
场景 A 是开始场景
场景B 是中间过渡场景
场景C 是最终需要到达(加载)的场景
准备好脚本:
我没有用button,而是用的gameobject作为点击事件 所以就有一点不同
AsyncLoadScene(此脚本是核心内容)
CubeEventItemBind(此脚本是cube的点击事件)
AddEeventMonoTest(此脚本是cube添加点击事件)
直接上
using UnityEngine;
using System.Collections;
using UnityEngine.UI;
using UnityEngine.SceneManagement;
public class Globe
{
public static string nextSceneName ;
}
public class AsyncLoadScene : MonoBehaviour
{
public Slider loadingSlider;
public Text loadingText;
private float loadingSpeed = 1;
private float targetValue;
private AsyncOperation operation;
// Use this for initialization
void Start()
{
loadingSlider.value = 0.0f;
if (SceneManager.GetActiveScene().name == "B")
{
//启动协程
StartCoroutine(AsyncLoading());
}
}
IEnumerator AsyncLoading()
{
operation = SceneManager.LoadSceneAsync("Scenen");
//阻止当加载完成自动切换
operation.allowSceneActivation = false;
yield return operation;
}
// Update is called once per frame
void Update()
{
targetValue = operation.progress;
if (operation.progress >= 0.9f)
{
//operation.progress的值最大为0.9
targetVa