赞
踩
新建Panel,颜色调成深灰色,不透明度255
Panel下新建Slider,调整Slider;Panel下新建Text,显示进度条百分比
新建empty GameObject,命名为LoadManagerGameObject
新建脚本LoadManager.cs,将脚本拖拽放到LoadManagerGameObject上,
将Panel的enabled取消勾选
新建Button,命名为下一关;OnClick()点击+,将Hierarchy中的LoadManagerGameObject拖拽到Object上,函数选择LoadNextLevel()
File-Build Settings,将现在的场景和要加载的场景拖拽到窗口中
LoadManager.cs
using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.UI; public class LoadManager : MonoBehaviour { public GameObject loadScreen; public Slider slider; public Text text; public void LoadNextLevel() { StartCoroutine(LoadLevel());//开启协程 } IEnumerator LoadLevel() { loadScreen.SetActive(true);//可以加载场景 AsyncOperation operation = SceneManager.LoadSceneAsync(SceneManager.GetActiveScene().buildIndex + 1); operation.allowSceneActivation = false;//不允许场景自动跳转 while(!operation.isDone)//场景加载没有完成时 { slider.value = operation.progress;//slider的值=加载的进度值 text.text = operation.progress * 100 + "%"; if (operation.progress >= 0.9F) { slider.value = 1.0f; text.text = "100%"; operation.allowSceneActivation = true;//允许场景自动跳转 } yield return null;//跳出协程 } } }
AsyncOperation
LoadManager
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。