首页 > 学院 > 开发设计 > 正文

unity 场景跳转初步优化——异步跳转

2019-11-08 03:10:36
字体:
来源:转载
供稿:网友
 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 () {}    PRivate void OnGUI()    {        if ( GUI.Button(new Rect(0,0,80,50),"点击"))        {            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 ;    }}
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表