How to load a level
I am trying to load a level after a button is pressed. I looked through this page: http://answers.unity3d.com/questions/58897/load-scene-on-button-press.html And followed what they said but it did not work, I also read this page: http://docs.unity3d.com/ScriptReference/Application.LoadLevel.html And yet I still can not figure it out. Here is my code: using UnityEngine; using System.Collections;
public class Play : MonoBehaviour {
// Use this for initialization
void onMouseDown () {
Application.LoadLevel("Level1");
}
// Update is called once per frame
void Update () {
}
}
Thanks for the responses but i am having a new problem, Well sort of diffrent
using UnityEngine; using System.Collections;
public class Level_select : $$anonymous$$onoBehaviour {
public int sceneToStart = 1;
// Use this for initialization
void Start()
{
if (Input.GetButton("Jump"))
{
Application.LoadLevel(2);
}
}
// Update is called once per frame
void Update () {
}
}
How is this not working? I am not great at scripting but these should work if i am not mistaken.
Answer by Suddoha · Sep 14, 2015 at 01:26 AM
There is a typo. It should be OnMouseDown (capital letter) instead of onMouseDown.
But there are other things to check, too:
OnMouseDown and similar functions are called when you click on an object that has a collider (you actually have to hit the collider, not only the mesh) or a GUIElement component, such as GUIText or GUITexture AND if that object has a script attached to it with a OnMouseDown() method.
In case you're working with the new UI system, this is not the way to go. In short: using the new UI system allows you to subscribe to events, e.g. onClick for buttons. But that's another story.
Answer by henkjanswek · Sep 13, 2015 at 06:57 PM
Make sure you added your level at the build settings.
File -> Build Settings -> Add current.
Your answer