So I don’t know what i’m doing wrong, but i’m using The UI buttons in unity 4.6 I have a start button and a how to button on the home page. I added a script to the start button you getmousebuttondown…Application.loadLevl. and that works all fine it takes me to the next level but when i click the how to button it goes to the same page. Even when i added the same script and changed the name it still goes to the same level as start. So i dont know if theres a certain way i have to set it up, because im very confused. plus the next window is the same thing but i have like six buttons thats suppose to go to there own level so can some help or guide me in the right directions please and thank you
The problem is you using getMouseButtonDown to handle several buttons, but getMouseButtonDown is triggered whenever user clicks the mouse in any location on screen. To make it work this way you should check on what button exactly the user clicked.
But there is a simpler approach, you can add new function to one of your gameobject’s (lets say it’s named GameManager) script that named for example MyUiController, that will handle only level loading, like this one:
public void LoadLevelNum(int num = 0){
Application.LoadLevel (num);
}
And then in the editor you can select your button, look in inspector for choose your “On Click ()”, add a plus sign there, choose or grag’n’drop your gameobject to field with “None (Object)”, then select your function from dropdown that says “No function”, like this:
Now this field will contain your function name (MyUiController.LoadLevelByNum), and below this line you can specify number of what level this button needs to load.
After this you can just duplicate button and enter new number, that way it’ll be simpler and faster. Or you add a handler to your existing buttons and spcify different levels.