unity中加載下一個場景且不銷毀當前場景的方法


1.

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

public class TEST : MonoBehaviour {

    public Button btn;

    public void Start()
    {
        btn.onClick.AddListener(() => Load());
    }

    public void Load()
    {
        AsyncOperation  ass=SceneManager.LoadSceneAsync("02",LoadSceneMode.Additive);
    }


}

代碼比較簡單 主要是了解

SceneManager.LoadSceneAsync(異步加載)的參數含義:

《1》public static AsyncOperation LoadSceneAsync(int sceneBuildIndex, LoadSceneMode mode);
    int sceneBuildIndex:是在scenes in build中場景的下標(一般不建議使用該方法)
    LoadSceneMode mode:LoadScenesMode 是個枚舉 有兩種
    
    // 摘要: 
    //     Used when loading a scene in a player.
    public enum LoadSceneMode
    {
        // 摘要: 
        //     Closes all current loaded scenes and loads a scene.
        Single = 0,
        //
        // 摘要: 
        //     Adds the scene to the current loaded scenes.
        Additive = 1,
    }

     single:關閉所有當前加載的場景並加載場景。
   Additive :將場景添加到當前加載的場景中

      

 

 



免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM