Load levels using new UI system (Unity 5)
I recently discovered how to load levels using the new UI system in Unity 5.
- Add a canvas to your scene.
- Add a button to your canvas.
- Create a new script as follows:
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);
}
}
- Create a new empty game object and attach the script.
- On the Button (Script) component of the button, select the empty game object under the On Click() box.
- Select the ButtonnextLevel.NextLevelButton (string) method in the upper right dropdown button.
- Enter the name of the level you want to load (must be a scene in the build settings).
Comments
Post a Comment