Hello, good day, I want to make several scenes that present a canvas and buttons and, depending on the buttons that the user clicks, it advances to the next scene, but it only does it once, even though I assigned the correct functions to the buttons in the (onclick) part and, in addition, I applied the code that chatgpt gave me. And they were already loaded in order in Build Settings, any help? Thanks
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class GameController : MonoBehaviour
{
public int score = 0;
private int questionIndex = 1;
private int totalQuestions = 5;
private static GameController instance;
void Awake()
{
if (instance == null)
{
instance = this;
DontDestroyOnLoad(gameObject); // Make the GameController persistent between scenes
}
else
{
Destroy(gameObject);
}
}
private void Start()
{
// Reset the question index and score on the first scene
if (SceneManager.GetActiveScene().name == "Question1")
{
questionIndex = 1;
score = 0;
}
}
public void AnswerA()
{
score += 10;
NextQuestion();
}
public void AnswerBOrC()
{
NextQuestion();
}
private void NextQuestion()
{
questionIndex++;
if (questionIndex <= totalQuestions)
{
SceneManager.LoadScene("Question" + questionIndex);
}
else
{
SceneManager.LoadScene("Result");
}
}
}