-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLevelAdditive.cs
More file actions
42 lines (34 loc) · 1.03 KB
/
LevelAdditive.cs
File metadata and controls
42 lines (34 loc) · 1.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using UnityEngine;
using UnityEngine.SceneManagement;
using System.Collections;
[RequireComponent (typeof (SphereCollider))]
public class LevelAdditive : MonoBehaviour {
public string level;
// Use this for initialization
void Start () {
GetComponent<Collider>().isTrigger = true;
}
void OnTriggerEnter(Collider other){
if(other.CompareTag("Player")){
// StartCoroutine(LoadAsync());
SceneManager.LoadSceneAsync(level, LoadSceneMode.Additive);
// SceneManager.SetActiveScene(SceneManager.GetSceneByName(level));
}
}
void OnTriggerExit(Collider other){
if(other.CompareTag("Player")){
SceneManager.SetActiveScene(SceneManager.GetSceneByName("Montreal"));
StartCoroutine(UnloadScene());
}
}
IEnumerator LoadAsync(){
AsyncOperation loading = SceneManager.LoadSceneAsync(level, LoadSceneMode.Additive);
loading.allowSceneActivation = false;
yield return loading;
loading.allowSceneActivation = true;
}
IEnumerator UnloadScene(){
yield return new WaitForEndOfFrame();
SceneManager.UnloadScene(level);
}
}