0

I'm using unity 5 and I tried to make a menu and it isn't working because I have button's in a panel and I cant associate them with methods. I have a script and I have the following code:

void Start () {

}
void Update () {
}
public void LoadScene(string name) {
    Application.LoadLevel(name);
}
public void quit()
{
    Application.Quit();
}

But when I try to associate one of my method's with a button they don't appear so I cant associate them and my methods are public.

Any suggestion as to how I can fix this?

update:

http://jforeparacoesauto.comli.com/stackunity.png

3 Answers 3

3

Actually I think I see your mistake. From the screenshot it looks like you dragged the script directly from the assets folder into that spot for the OnClick, but you need to drag the gameobject that has that script on it from the scene into that spot.

This shows how it should be done (the object dragged has to have the script): https://youtu.be/J5ZNuM6K27E?t=9m45s

Sign up to request clarification or add additional context in comments.

Comments

1

You ll have to attach the script to a game object then attach the object to the onclick on the button. Then you would just have to choose what method to use. P.s you should move this to game development.

4 Comments

youtube.com/watch?v=vfi4ZYHR-MU i was following this tutorial and i did the same but for him the methods appeared and for me it didnt
Could you printscreen one of the buttons that isnt working?
Just to make sure, that script is actually attached to your LevelManager gameobject?
You seem to have the script attached, not the game object. You should have the game object ,which contains the script, attached to the onclick on the button.
1

Drag your script ontop of the button object, in the list of suggestions find the name of your script and select the method that you want to invoke when the button is being clicked.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.