How to change back to a previous scene in the Build Settings

Updated on July 8, 2017 in [A] Other Answers
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
4 on July 7, 2017

So I finished watching the most recent “Make your own game” from Brackeys (The one with the red cube and you have to dodge the black obstacles) and I finished a couple days ago, but I wanted to add some extra things. One of those extra things I made is a button that takes me back to the main menu on the end/credits scene. At first, I thought I could just use this ” SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex – 5); ” but whenever I drag this onto the “on click” script slot for my button, it gives me two functions. Either, No function, or Monoscript (which just leads to a side bar that says “string name” 

 

 

 

Just to restate, I need help with loading up my first scene which is a main menu after pushing my “Return to Main Menu” button (which is the second to last scene [ I have a bonus “endless mode” that you can get to from the main menu])

 

 

 

If you need screenshots or anything like that, feel free to ask :^)

  • Liked by
Reply
2 on July 7, 2017

You need the create a script with a public method and assign that method to the button

on July 7, 2017

So far I’ve done this:

 

using UnityEngine.SceneManagement;
using UnityEngine;

public class Backtomain : MonoBehaviour
{

public void LoadLevel()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex – 5);

}
}

But it still doesn’t work, can you tell me what’s wrong please?

Devoted
on July 8, 2017

Define “doesn’t work”. You need to clarify what is working and what isn’t. Also why are you then going -5 in the build settings, shouldn’t it be -1?

Show more replies
  • Liked by
Reply
Cancel
0 on July 8, 2017

 

public void ChangeScene(int index)
 
{
 
SceneManager.LoadScene(index);
 
}

 

  • Liked by
Reply
Cancel