initial commit
This commit is contained in:
38
Assets/Scripts/LevelExit.cs
Normal file
38
Assets/Scripts/LevelExit.cs
Normal file
@@ -0,0 +1,38 @@
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user