65 lines
1.2 KiB
C#
65 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class ScenePartLoader : MonoBehaviour
|
|
{
|
|
[SerializeField] private bool isLoaded;
|
|
[SerializeField] private bool shouldLoad;
|
|
|
|
//private void Update()
|
|
//{
|
|
|
|
//}
|
|
|
|
void LoadScene()
|
|
{
|
|
if (!isLoaded)
|
|
{
|
|
SceneManager.LoadSceneAsync(gameObject.name, LoadSceneMode.Additive);
|
|
isLoaded = true;
|
|
}
|
|
}
|
|
|
|
void UnLoadScene()
|
|
{
|
|
if (isLoaded)
|
|
{
|
|
SceneManager.UnloadSceneAsync(gameObject.name);
|
|
isLoaded = false;
|
|
}
|
|
}
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (other.CompareTag("Player"))
|
|
{
|
|
shouldLoad = true;
|
|
TriggerCheck();
|
|
}
|
|
}
|
|
|
|
private void OnTriggerExit(Collider other)
|
|
{
|
|
if (other.CompareTag("Player"))
|
|
{
|
|
shouldLoad = false;
|
|
TriggerCheck();
|
|
}
|
|
}
|
|
|
|
void TriggerCheck()
|
|
{
|
|
if (shouldLoad)
|
|
{
|
|
LoadScene();
|
|
}
|
|
else
|
|
{
|
|
UnLoadScene();
|
|
}
|
|
}
|
|
|
|
}
|