- Home /
Problem loading scene on
I am trying to get button to load new scene when clicked but when I click anywhere it happens Here is my code:
#pragmastrict
functionUpdate () {
if(Input.GetMouseButton(0))
Application.LoadLevel("TEST");
}
Please help
Yep what @tanoshimi said, so busy looking at your functionUpdate I never saw the rest of the problem :D
I think he wants to load the level on the buttonClick event, not on mouseDown event
What did you refer with "click anywhere"? The method Input.Get$$anonymous$$ouseButton(0) receives clicks from everywhere on the game window.
What i mean is how would i get clicks from just the button?
Answer by taxvi · Dec 15, 2014 at 06:04 PM
function OnGUI(){
if(GUI.Button(new Rect(50, 50, 200, 40), "load new level"){
Application.LoadLevel("TEST");
}
}
You were confused by the method's name. Get$$anonymous$$ouseButton doesn't mean that there is a button in the scene, it refers to the mouse's button.
this code creates a button on the screen, and I think this is exactly what he wants
There is a syntax error in your code because when I try to run it, it comes up with errors Assets/Onclick.js(3,56): BCE0044: expecting ), found '{'. Assets/Onclick.js(6,1): BCE0044: expecting EOF, found '}'.
It is missing a ) bracket, change this line to this :
if (GUI.Button(new Rect(50, 50, 200, 40), "load new level")) {
and hopefully the error will be gone.
Your answer
![](https://koobas.hobune.stream/wayback/20220613174112im_/https://answers.unity.com/themes/thub/images/avi.jpg)