異步加載

using System;
using System.Collections;
using System.Collections.Generic;
using System.Reflection.Emit;
using UnityEngine;
using UnityEngine.UI;
using UnityEngine.SceneManagement;


public class Material : MonoBehaviour
{

    public Slider slider;//進度條
    AsyncOperation a;//異步加載對象
    float temp;
    private void Start()
    {
        slider.value = 0;
        StartCoroutine(Demo1());
    }

    private IEnumerator Demo1()
    {
        a= SceneManager.LoadSceneAsync(2);
        a.allowSceneActivation = false;
        yield return a;
    }
    private void Update()
    {


        if (a.progress >= 0.8)
        {
            temp = 1;
        }
        else
        {
            temp = a.progress;
        }


        slider.value =  Mathf.Lerp(slider.value, temp, Time.deltaTime);
         
        
        if (Mathf.RoundToInt(slider.value*100) ==100)
        {            
            a.allowSceneActivation = true; 
        }
       
    }
}

發佈了58 篇原創文章 · 獲贊 2 · 訪問量 2萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章