Unity script to open a new scene

Hello, I'm trying to open a scene using this script. But every time I click the button, it just quits the game.

function OnGUI () {
    if (GUI.Button (Rect (10,120,150,100), "Play Game")) {
        EditorApplication.OpenScene("Assets/CharacterSelection.unity");
    }
}

Hi,

Are you trying to build an authoring tool? or is it within your game? If you want to open a scene within your game, then you should use

Application.LoadLevel("characterSelection");

Bye,

Jean

http://unity3d.com/support/documentation/ScriptReference/Application.LoadLevel.html

Enjoy and have a good night!

If you are currently working with scenes then use SceneManager.LoadScene(string); as Application.LoadLevel(string); is Deprecated.

The usage is as follows:

using UnityEngine;
using UnityEngine.SceneManagement;

public class ExampleClass : MonoBehaviour
{
    void Start()
    {
        // Only specifying the sceneName or sceneBuildIndex will load the Scene with the Single mode
        SceneManager.LoadScene("OtherSceneName", LoadSceneMode.Additive);
    }
}