您最多选择25个主题
主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
26 行
835 B
26 行
835 B
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class SceneLoadScript : MonoBehaviour
|
|
{
|
|
public string scenePath; //path of scene to load inside "Assets" without scenename e.g. here "SeemlessSceneLoadDemo/Scenes/"
|
|
public string sceneName; //scenename e.g. "myScene"
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
bool isSceneLoaded = false;
|
|
//first check if scene is already loaded
|
|
for (int i = 0; i < SceneManager.sceneCount; i++)
|
|
{
|
|
if (sceneName.Equals(SceneManager.GetSceneAt(i).name))
|
|
{
|
|
isSceneLoaded = true;
|
|
}
|
|
}
|
|
if (!isSceneLoaded)
|
|
{
|
|
SceneManager.LoadScene(scenePath+ sceneName, LoadSceneMode.Additive);
|
|
}
|
|
}
|
|
}
|