39 lines
1.1 KiB
C#
39 lines
1.1 KiB
C#
using UnityEngine;
|
|
using UnityEngine.SceneManagement;
|
|
|
|
public class LevelExit : MonoBehaviour
|
|
{
|
|
[SerializeField] private string nextSceneName = "Level 2";
|
|
[SerializeField] private bool loadNextBuildIndex = false;
|
|
|
|
private bool isTransitioning = false;
|
|
|
|
private void OnTriggerEnter(Collider other)
|
|
{
|
|
if (isTransitioning) return;
|
|
|
|
if (other.CompareTag("Player"))
|
|
{
|
|
isTransitioning = true;
|
|
if (loadNextBuildIndex)
|
|
{
|
|
int nextIndex = SceneManager.GetActiveScene().buildIndex + 1;
|
|
if (nextIndex < SceneManager.sceneCountInBuildSettings)
|
|
{
|
|
SceneManager.LoadScene(nextIndex);
|
|
}
|
|
else
|
|
{
|
|
Debug.Log("No more scenes in build settings. Reloading current scene.");
|
|
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
|
|
}
|
|
}
|
|
else if (!string.IsNullOrEmpty(nextSceneName))
|
|
{
|
|
SceneManager.LoadScene(nextSceneName);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|