how do I change a scene once a button is pressed

Hi, I want to know how to change a scene once a button is pressed. I want it to be a c# script that I can just equip to a button. I also want to know if the code will recognise a scene if its in a folder (like the default scenes folder created by unity). thanks in advance
ps: I have a base to help scripting here: how do I change a scene once a button is pressed - Unity Forum

Have you considerd Googling? It’s NOT just a script. It’s a lot of setup.

6934017--814392--Screen Shot 2021-03-14 at 12.03.18 PM.png

Hello, should I re-phrase the question?
Can you please help me make this… work

using UnityEngine;
using UnityEngine.SceneManagement;
public class play : MonoBehaviour
{
    void Update()
    {
        public void OnButtonPress(){
        SceneManager.LoadScene("game");
    }
  
    }
}

Thanks in advance!

Hi. You don’t want to put the OnButtonPress() function inside the Update function. It should look more like this.

using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

public class play : MonoBehaviour
{
    public Button loadSceneButton;

    void Start()
    {
        loadSceneButton.onClick.AddListener(OnButtonPress);
    }

    void Update()
    {
    }

    public void OnButtonPress()
    {
        SceneManager.LoadScene("game");
    }
}

This ^ ^ ^ Now the script is PERFECT. RageByte has made it precisely what you need.

But… code is only about 10% of the problem.

Now you need to connect the script to the button. Rather than one of us attempting to type the 27 steps required, it’s probably easier for you to look at one of the tutorials as I originally suggested.

1 Like

omg tysm
I have been searching for so long lol!