Changing Scene When Button Tapped

Hi. I created a button by going to create > ui > button. How would I change the scene if the button is clicked or tapped? I know it isn’t OnGUI(), right? Please help. Thanks!

You can do:

Application.LoadLevel (Destination);

//FOR EXAMPLE
Application.LoadLevel ("PlayScene2");

Remember, in order for this to work you must open the file > build setting and drag and drop the scenes you are gonna use into the build settings.

REF:

//EDIT//
BTW what i do is create this simple script:

//LOAD LEVEL SCRIPT
#pragma strict

var Destination : String;

function LoadScene () {
	Application.LoadLevel (Destination);
}

Attach it to the button that loads levels and on the inspecter type in the desire scene destination, then add an event to the button component and use the button it self to execute the LoadScene() function.

Here is another answer about this topic:

//EDIT//

HOW TO DO IT

1.select you button, on the inspector you must have a “button” component if not add it.

2.Then drag and drop the object with the loadlevel script

3.Select the script > function() and when the button gets clicked or taped the selected function will be executed.


I recommend you to watch this video shows everything you need to know (Almost)

For your button, there is a place that says “OnClick()” And then some extra stuff here.

If you want to load a scene, when a button is pressed. You first need to have a script up with a function to load a scene, and this script must be attached to an object you refer to. I use my script on the entire “Canvas” parent!

In this script. Create this method, and it has to be public!

public void LoadStage()  {
    Application.LoadLevel ("YourLevel");
}

In the image I attached, you can see how it looks like for the button! So, whenever this button is clicked (OnClick()), it will see that I reference a script on a gameObject, and a specific method as well! This will exute the method when pressed.

Do like this (Inside OnGUI() function)

    if(GUI.Button (start, "Start Game"))
	{
		Application.LoadLevel("SceneName");
	}

I do this:
if (Input.GetMouseButtonUp(0)) {
Application.LoadLevel (“Scene name here”);
}

//first do this

using UnityEngine.SceneManagement;

//then use this code

SceneManager.LoadScene(index);

//OR

Application.LoadLevel (index);

//index is index of your scene

in the button i already put the button , but in no function i already click but just have a “String Name” the code is same with ur , please help me im urgent

I know this is an old thread, but here is How To Change Scenes in Unity 2017! VR HOW TO CHANGE SCENES IN UNITY 2017 - YouTube