赞
踩
目录
将需要加载的场景拖拽进去
直接打开该场景
- using UnityEngine.SceneManagement;
- ……………………
- void Start()
- {
- SceneManager.LoadScene("SampleScene");
- }
打开一个场景和附加打开场景
附加打开会将两个场景中的物体叠加在一起
- //单个打开
- SceneManager.LoadScene("SampleScene", LoadSceneMode.Single);
- //附加打开
- SceneManager.LoadScene("SampleScene", LoadSceneMode.Additive);
- Scene scene = SceneManager.GetActiveScene();
- Debug.Log(scene.name);
- //获取当前场景名称
- Scene scene = SceneManager.GetActiveScene();
- Debug.Log(scene.name);
- //场景是否已经加载
- Debug.Log(scene.isLoaded);
- //路径
- Debug.Log(scene.path);
- //索引
- Debug.Log(scene.buildIndex);
-
- //返回场景的对象数量
- GameObject[] gos = scene.GetRootGameObjects();
- Debug.Log(gos.Length);
-
- //创建新场景
- Scene newS= SceneManager.CreateScene("123");
-
- //卸载新场景
- SceneManager.UnloadSceneAsync(newS);
-
- //场景管理类:检测多少已加载的活动场景
- Debug.Log(SceneManager.sceneCount);

- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using UnityEngine.SceneManagement;
-
- public class Async : MonoBehaviour
- {
- AsyncOperation operation;//场景异步加载
- float Timer=0;
- void Start()
- {
- StartCoroutine(LoadScene());//开启一个协程
- }
-
- IEnumerator LoadScene()
- {
- operation = SceneManager.LoadSceneAsync("SampleScene");//指定加载的场景,可以是数字,加载场景的序号
- operation.allowSceneActivation = false;//不允许场景自动跳转
- yield return operation;
-
- }
- void Update()
- {
- Debug.Log("加载进度:"+operation.progress);//加载进度(0~0.9)
- if (operation.progress >= 0.89)
- {
- Debug.Log("场景已加载完毕");
- }
- Timer += Time.deltaTime; //计数器累加
- if (Timer > 5) //5秒后跳转
- operation.allowSceneActivation = true;
- }
- }

其他
按X快捷键让当前编辑物体是处于世界坐标系还是相对坐标系下。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。