using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class GameStarter : MonoBehaviour
{
    [SerializeField] int startScene = 1;
    private int currentscene;
    private int nextscene;

    private void OnEnable()
    {
        StopRecordingTrigger.OnRecordStop += HandleRecordStop;
    }

    private void OnDisable()
    {
        StopRecordingTrigger.OnRecordStop -= HandleRecordStop;
    }

    private void Awake()
    {
        DontDestroyOnLoad(this);
        currentscene = startScene;
    }

    // Update is called once per frame
    void Update()
    {
        if (OVRInput.GetDown(OVRInput.Button.SecondaryIndexTrigger))
        {
            if (SceneManager.GetActiveScene() != SceneManager.GetSceneByBuildIndex(startScene)) return;
            nextscene = currentscene + 1;
            currentscene = nextscene;
            StartGameByLoadingScene(nextscene);
        }
    }

    void StartGameByLoadingScene(int sceneIndex)
    {
        SceneManager.LoadScene(sceneIndex);
    }

    private void HandleRecordStop()
    {
        StartGameByLoadingScene(startScene);
    }
}
