- Home /
Can't get 4.6 GUI Button to Load Scene (Solved)
I'm just starting with the new Unity 4.6 UI and thought I'd try something easy like loading a scene using a GUI button. I've made a simple javascript to load my level and have it attached/listed under the 'On Click' section for my button.
#pragma strict
function LoadScene ()
{
Application.LoadLevel("Arena01");
}
I'm not getting any errors but when I click the appropriate button... nothing !
(I have the scene listed in my build)
(Scene name in the script and actual scene name are exactly the same)
Any ideas guys ???
Answer by Mmmpies · Jan 04, 2015 at 09:09 AM
Just tried that script and the only thing I changed was the name of the scene so it matched a scene in my game and it worked fine.
Is your OnClick setup like this?
No. Where you have the "loadScene.LoadScene" dropdown, I only have 'no function' or 'monoscript' options ?
I just closed and re-opened unity and now its kind of working. However it now just immediately jumps to the load screen and my cursor is immediately off screen causing it to tab out (don't think this would affect a standalone build though)
???
In the slot below "Runtime Only" have you dragged the button onto that?
That assumes your script is on the button.
No I hadn't. Have now, but same effect.. auto jumps straight to the next scene without the button being pressed ?
And your script hasn't changed at all?
It sounds like it's running the script on Awake or Start rather than when that function is called.
What you should do is create the button, add the script to it. Add the onClick event. Drag your button the empty slot and then select the script->function from the drop down.
Your answer
Follow this Question
Related Questions
GUI Button Disappearing 1 Answer
I have doubt please help me 2 Answers
Unity buttons touchscreen woes 0 Answers