Can UI buttons load scenes?

If they can, how can this be done, to switch from one scene to the next?

Lets say it’s 4.6 and the new UI.

I create a Canvas.(Add a canvas to the Hierarchy in the inspector for the scene)
I Add a UI->Button to the canvas.

I create a script(ButtonNextLevel.cs), i figure i want to support level change by level name(string) and by level int(the index number in build settings).

using UnityEngine;
using System.Collections;

public class ButtonNextLevel : MonoBehaviour 
{
	public void NextLevelButton(int index)
	{
		Application.LoadLevel(index);
	}

	public void NextLevelButton(string levelName)
	{
		Application.LoadLevel(levelName);
	}
}
  1. I save this.
  2. I add an empty game object. I attach my new script.
  3. I associate this game object with my new script to the Button(in the inspector) by: Clicking the +(plus) button to add a callback from an object->script->method.
  4. Furthermore i drag and drop that game object with the new script to the object box under On Click (). I select either ButtonNextLevel.NextLevel(int) or ButtonNextLevel.NextLevel(string)
  5. I specify either the level name or index based off the method i selected.
  6. I am good to go.

Lets say in 4.5.x or less:

public void OnGUI()
{
	if (GUI.Button(new Rect(10, 70, 50, 30), "Click"))
		Application.LoadLevel("level2");
}

You guys made this way too confusing. Make an empty gameobject, create new script in that gameobject.
Then put the script below in to the script file.
Go to the button you want to load the scene, hit the + sign under On Click () attach the gameobject the script is attached to where it says none push play, click the button, load the scene.

C# Script:
using UnityEngine;
using UnityEngine.SceneManagement;

public class scriptname : MonoBehavior {
public void OnMouseButton()
{
SceneManager.LoadScene(“yourscenename”)
}
}

P.s. Make sure your scene is added under file, build setting, add open scene. Oh and just in case make sure you have the scene you want to load open when you click add open scene.

If your looking for java the code I made/use is

#pragma strict
public var Level = "0";

function LoadLevel(){
Application.LoadLevel(Level);
}

Just simply attach it to a empty and use it on the OnClick() function on the button and select the function LoadLevel!

type in on a c# script-

 using UnityEngine;
 using System.Collections;
 
 public class ButtonNextLevel : MonoBehaviour 
 {
     public void NextLevelButton(int index)
     {
         Application.LoadLevel(index);
     }
 
     public void NextLevelButton(string levelName)
     {
         Application.LoadLevel(levelName);
     }
 }

then you will be good

using UnityEngine;
using System.Collections;

public class ButtonNextLevel : MonoBehaviour
{
public void NextLevelButton(int index)
{
Application.LoadLevel(index);
}

  public void NextLevelButton(string levelName)
  {
      Application.LoadLevel(levelName);
  }

}
they will have errors