赞
踩
一个滑动条,一个按钮
新建脚本async.cs
- using UnityEngine;
- using System.Collections;
- using UnityEngine.SceneManagement;//命名空间场景跳转
- using UnityEngine.UI;
-
- public class async : MonoBehaviour
- {
-
- AsyncOperation asy; //协程的变量
- public Slider slider;
- float value = 0;//滑动条的值
- void Start()
- {
-
- }
- public void OnClick()
- {
-
- StartCoroutine(LoadScene());
-
- }
-
- // Update is called once per frame
- void Update()
- {
- if (asy == null)
- {
- return;
- }
- int jd = 0;
- if (asy.progress < 0.9f)
- {
- jd = (int)asy.progress * 100;
-
- }
- else
- {
- jd = 100;
- }
- if (value < jd)
- {
- value++;
-
- }
- slider.value = value / 100;
- if (value == 100)
- {
- asy.allowSceneActivation = true;
- }
-
- }
- IEnumerator LoadScene()
- {
- asy = SceneManager.LoadSceneAsync(1);
- asy.allowSceneActivation = false;
- yield return asy;
- }
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。