using UnityEngine; using UnityEngine.SceneManagement; using UnityEngine.EventSystems; namespace HPJ.Examples { public class SceneLoader : MonoBehaviour { private void Update() { if (EventSystem.current.currentSelectedGameObject != null) { return; } if (Input.GetKeyDown(KeyCode.KeypadMinus)) { LoadPreviousScene(); } else if (Input.GetKeyDown(KeyCode.KeypadPlus)) { LoadNextScene(); } } public void LoadNextScene() { int currentSceneIndex = SceneManager.GetActiveScene().buildIndex; int nextSceneIndex = currentSceneIndex + 1; if (nextSceneIndex == SceneManager.sceneCountInBuildSettings) { nextSceneIndex = 0; } SceneManager.LoadScene(nextSceneIndex); } public void LoadPreviousScene() { int currentSceneIndex = SceneManager.GetActiveScene().buildIndex; int previousSceneIndex = currentSceneIndex - 1; if (previousSceneIndex < 0) { previousSceneIndex = SceneManager.sceneCountInBuildSettings - 1; } SceneManager.LoadScene(previousSceneIndex); } } }