重新加载场景,异步加载场景

来源:互联网 发布:新闻 数据集 编辑:程序博客网 时间:2024/06/05 04:30

//异步加载场景

using UnityEngine;

using System.Collections;
using UnityEngine.SceneManagement;

public class JumpScene : MonoBehaviour {


    void Start()

    {

                                                                                   //当前场景名字

        if (SceneManager.GetActiveScene().name == "StartSceneName")

        {

                                                    //跳转场景名字

            StartCoroutine(Loading("GameSceneName"));
        }
     }
    public IEnumerator Loading(string scenceName)
    {
        float f = 0;
        float time = 2f;
        AsyncOperation asy = Application.LoadLevelAsync(scenceName);

        asy.allowSceneActivation = false;

        //两秒后跳转

        while (f <= time)
        {
            f += Time.deltaTime;
            yield return new WaitForEndOfFrame();
        }
        asy.allowSceneActivation = true;

    }


    //重新加载场景

      SceneManager.LoadScene(SceneManager.GetActiveScene().name);   //获取当前场景的名字,然后跳转

原创粉丝点击