LoadScene not working
Hi Guys, i'm currently working on a Thesis project right now, and i've already reached the Credits section of the game, where i made it only with mouse click to change the text according to the string Index, but the problem right now is that i can't return to Scene 0 (Main Menu) when i reached the last string index. here's how the code goes:
void Update()
{
CreditsText.text = CreditSequence[TextIndex].ToString();
if (Input.GetMouseButtonDown(0)) {
sequence();
}
Debug.Log(TextIndex);
Debug.Log(CreditSequence.Count);
}
public void sequence() {
if (TextIndex < CreditSequence.Count-1)
{
CreditsText.text = CreditSequence[TextIndex].ToString();
TextIndex++;
}
else if (TextIndex == CreditSequence.Count)
{
Debug.Log("backtoMainMenu");
SceneManager.LoadScene(0);
}
}
there is no bug already, but the debug won't show anything. i still don't understand why it won't load the first scene. it was on the last scene. anybody know why?
Answer by jmhoubre · Jul 20, 2020 at 09:18 PM
Hello,
I see that in the sequence () method, an action is performed for numbers strictly smaller than CreditSequence.Count - 1 and for CreditSequence.Count, but not CreditSequence.Count - 1. There is surely a problem here. I think when TestIndex is CreditSequence - 1, it doesn't increase anymore, and the else if case never happens. What do the latest Debug.Log (TestIndex) give?
I also suggest you add this:
private void TestSequence () {
SceneManager.LoadScene (0);
}
and in the Update () method, to temporarily replace sequence () by TestSequence () in order to verify that the menu is launched well.
It would be better to post all the code for the class.
Good luck (and sorry for any mistakes in English).
Your answer
Follow this Question
Related Questions
Is having a List in an interface increasing overhead 1 Answer
Going NUTS- Tring to return a list from another script 3 Answers
Passing Score from Game Scene to Game Over Scene usiing dontDestroyOnLoad C# 1 Answer
How to delete an object if there is another object of the same type at that position ? 1 Answer