Files
LowPolyFPS/Assets/Scripts/LevelExit.cs

39 lines
1.1 KiB
C#
Raw Normal View History

2026-10-12 21:28:47 +01:00
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);
}
}
}
}